Reputation:
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? :-)
Upvotes: -1
Views: 156
Reputation: 346377
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.
Upvotes: 2
Reputation: 20985
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.
Upvotes: 0