I am developing a website with several pages with more to be added. Is there a way to develop the menu list in an attached file (such as a .css) so I can edit or add to the menus by editing this one file and have it reflected in all the pages, without having to recode (edit) each individual page?

Any help would be greatly appreciated.
Mike

PappaJohn

05-06-2007, 07:43 AM

Not sure how much help this will be, but ...

I use the Smarty Template Engine (http://smarty.php.net/), not specifically for the use you describe, but it is a perfectly valid use for smarty.

I'd create the page header and page footer as separate template files (html). The header file contains everything from "<!DOCTYPE HTML PUBLIC ..." down through the end of the markup that will remain the same on all pages. The footer file contains all the markup that will remain constant across all pages, down through "</html>".

Then separate template files are created for each page. These files contain all the page content between the header and footer. Then the Smarty 'include' function is used to include the header/footer templates.

So, something like this:

body.tpl

{include file="header.tpl"}

... all page content goes here

{include file="footer.tpl"}

Then anytime you need to change the header, you simply edit the header.tpl file and the change is reflected site-wide.

The use of .tpl extension is personal preference - it's perfectly valid to use the .htm file extension if you prefer.

This may be a bit overkill for your use, but it is one option (I use this method since most pages I design contain dynamic content).

Hope this makes sense.

Excavator

05-06-2007, 04:04 PM

I am developing a website with several pages with more to be added. Is there a way to develop the menu list in an attached file (such as a .css) so I can edit or add to the menus by editing this one file and have it reflected in all the pages, without having to recode (edit) each individual page?

Any help would be greatly appreciated.
Mike

Hello Mike,
I use a .php include for menus all the time to do exactly what your wanting.
Have a look at http://www.w3schools.com/php/php_includes.asp

tsguitar2004

05-07-2007, 07:38 AM

It's all about PHP includes. I originally read this on A List Apart (http://www.alistapart.com/articles/keepingcurrent/). That's a good read and should get you all set up. This is a priceless method and I can't imagine maintaining a site without it now. I use them all over the place.
-ts