views:

56

answers:

1

As one of the steps toward a greater website redesign I am putting the majority of the content of our website into html files to be used as includes. I am intending on passing a variable to the PHP template page through the URL to call the proper include.

Our website has many programs that each need an index page as well as about 5 sub-pages. These program pages will need a menu system to navigate between the different pages.I am naming the pages pagex_1, pagex_2, pagex_3, etc. where "pagex" is descriptive of the page content.

My question is, what would be the best way to handle this menu system? Is there a way to modify the initial variable used to arrive at the index page to create links in the menu to arrive at the other pages?

Thanks for any help!

A: 

I'd store the menu structure in an associative PHP array like so:

$menu = array(
  'index'=>array(
     'title'=>'Homepage',
     'include'=>'home.html',
     'subitems'=>array()
  ),
  'products' => array(
     'title'=>'Products',
     'include'=>'products.html',
     'subitems'=>array(
        'product1'=>array(
           ...
        ),
        'product2'=>array(
           ...
        ),
        'product3'=>array(
           ...
        )
     )
  )
);

Make that array available to the template script as well (e.g. by include/require). Then use delimiters in the variable to identify the menu item (like a file system does with folders and files) and therefore the resulting page to be included:

  • 'index' would identify the index page
  • 'products' would identifiy the products start page
  • 'products/product1' would identify the product 1 subpage inside the products page

... and so on.

Robert