tags:

views:

37

answers:

3

let's say I'm working on a site that has 8 to 10 different html/php templates

I want to use several common elements on every page, like most people do, masthead, footer, sidebar, the usual

but these common elements often need minor adjustments for each template, like one template has sub navigation in the sidebar and one does not

I'm wondering what approach is best

option 1 should I have a separate include or require for each different common element, like one for the html head one for footer, one for the sidebar, etc

option 2 should I require just one larger file that holds all my common elements, and then I can use $_SERVER['SCRIPT_NAME'] and conditionals to test which template is being called and make modifications to the common elements as needed

Does it really make any difference as far as performance goes or load on the server? how many conditionals is too many? how many includes is too many?

am I making sense folks? :-)

A: 

Would it matter? If the template is not needed it wouldn't be included right? As far as I know having more files on a server, as long as they are not in use, doesn't effect server load.

Ben Shelock
A: 

If you're early on in your development and you have the ability to switch to a new framework, you might want to try an MVC framework like CakePHP.

xanadont
+1  A: 

Your priority should be maintainability, not performance. And for that reason, it's definitely preferable to have multiple templates that are included as required. Ideally, adjustments should be expressed through parameters/flags i.e. have the main script set $showSubnavigation=true and the navigation template tests for that rather than for the name of the main script. Better yet, implement the navigation template as a function that you can call with parameters.

Michael Borgwardt
sounds good, I guess I was worried that calling 3 to 5 includes every time a page is viewed would just be too much
mjr
Premature optimization. The things that actually cause performance problems are rarely those you think of.
Michael Borgwardt