I'm building a site with a consistent header and footer area. Nothing special -- the header has a logo and a navbar with rollovers that link to different sections, and the footer has some basic site and copyright info. The contents of these are the same across all the pages, except that the navbar needs to be adjusted to indicate the section that the user is currently in. I want to put the header and footer code into separate external files and then include them into my other pages so that, when I change the navbar, I only have to change it in one place. In other words, the usual sort of thing.
When I've done this before, I've define a special variable in the page receiving the included file, something like:
$currentSection = "home";
I then write the header file to test the value of $currentSection and produce HTML that will produce the proper nav bar -- in this case, with a "you're here" icon for the home nav item and "click to go here" icons for the other items. My question is then: What's the best (i.e., most efficient) way to structure the header file and do the conditionalizing? I can think of two ways:
(1) The header file has a sequence of tests for each nav bar item -- for each one, see if it corresponds to $currentSection; if it does, show this; if it doesn't, show that. This produces a relatively short file, but with a bunch of separate tests.
(2) The header file has one big switch statement that says, in effect, "if $currentSection is 'home', then use this navbar (followed by the HTML for such a navbar), else if $currentSection is 'section1', then use this navbar", and so on. This produces a relatively long file with a lot of stuff to be parsed, but with only one test (depending on how you think about switch statements, anyway).
One could get philosophical about all sorts of aspects of this; my current concern is whether there are obvious performance reasons, based on the internals of PHP, that would argue for one approach over the other. Or, if there's a better way to do this, please let me know.
Thanks,
Jim