Code Comments
Programming Forum and web based access to our favorite programming groups.I am want to use a menu in all my web pages. So when I replace the menu for another I would like to see all the other pages change too. In C I could use an include in the preprocessor stage. Is there something in PHP or html?
Post Follow-up to this message"fed" <u@dds.nl> wrote in message news:c_N7e.3531$HP5.2080@newsfe01.lga... >I am want to use a menu in all my web pages. > So when I replace the menu for another > I would like to see all the other pages change too. > > In C I could use an include in the preprocessor stage. > Is there something in PHP or html? In php there is. Magically it's called include. <?php include "my_menu.txt"; ?> Example.php: <html><head></head> <body> <?php include "my_menu.txt"; ?> Blaah blaah bblaah </body> </html> my_menu.txt: <p>Here's my übermenu</p> -- Welcome to Usenet! Please leave tolerance, understanding and intelligence at the door. They aren't welcome here. eternal piste erection miuku gmail piste com
Post Follow-up to this messagefed wrote: > I am want to use a menu in all my web pages. > So when I replace the menu for another > I would like to see all the other pages change too. > > In C I could use an include in the preprocessor stage. You could...but you shouln't. > Is there something in PHP or html? Yes, both. RTFM http://uk2.php.net/function.include C.
Post Follow-up to this messageOn Fri, 15 Apr 2005 13:56:51 +0200, fed wrote: > I am want to use a menu in all my web pages. > So when I replace the menu for another > I would like to see all the other pages change too. > > In C I could use an include in the preprocessor stage. > Is there something in PHP or html? You want a common piece of code to be run on all the pages of your application, and you want to be able to modify this code in only one centralized location, so that the modification will then occur for your entire application. Is that what you wish? You can do this with PHP. Create a function, or a class, which produces the menu, and call this function (or instantiate the class) on each page where the menu is to appear. Put the function (or class) in a php file of its own, along with other common functions and classes. Then "include" this code in any php script which needs it with a require statement (require $filename where $filename is the name of the file, and possibly its path if not located where expected by php). If your code is very complicated and you start to have problems including the same files multiple times (giving you errors), you could use require_once instead. To make changes, you can edit the function or class. Or you can make the function or class be dynamic, by having it determine its output (i.e. its generated html code) based on for example reading another file with a require statement (this time perhaps only text), or a switch statement (if you have set types of menus you want to always choose between) or from a database. This latter really gives you full flexibility of what you can do.
Post Follow-up to this messageOn Fri, 15 Apr 2005 13:56:51 +0200, fed wrote: > I am want to use a menu in all my web pages. > So when I replace the menu for another > I would like to see all the other pages change too. > > In C I could use an include in the preprocessor stage. > Is there something in PHP or html? You want a common piece of code to be run on all the pages of your application, and you want to be able to modify this code in only one centralized location, so that the modification will then occur for your entire application. Is that what you wish? You can do this with PHP. Create a function, or a class, which produces the menu, and call this function (or instantiate the class) on each page where the menu is to appear. Put the function (or class) in a php file of its own, along with other common functions and classes. Then "include" this code in any php script which needs it with a require statement (require $filename where $filename is the name of the file, and possibly its path if not located where expected by php). If your code is very complicated and you start to have problems including the same files multiple times (giving you errors), you could use require_once instead. To make changes, you can edit the function or class. Or you can make the function or class be dynamic, by having it determine its output (i.e. its generated html code) based on for example reading another file with a require statement (this time perhaps only text), or a switch statement (if you have set types of menus you want to always choose between) or from a database. This latter really gives you full flexibility of what you can do.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.