Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP includes -- include the content or the code?

I can't decide which approach makes more sense.


mick shrimpton

8:31 pm on Nov 5, 2003 (gmt 0)

10+ Year Member

Please give me your thoughts on the pros and cons of these two approaches. Which would/do you do?

Approach 1 -- Include the Content
E.g. a file named template.php loads content with a variable, template.php?content=thispage

template.php would work like this:

code . . . <include thispage> . . . code

Approach 2 -- Include the Layout
Every page would have its own file, e.g. thispage.php, which would work something like this:

<include top> . . . content here . . . <include bottom>

Which approach is better? Why?

Thanks for your help!


11:01 pm on Nov 5, 2003 (gmt 0)

10+ Year Member

Both approaches effectively do the same thing, ie include data from other files to build a page.

I always opt for whatever requires the least amount of work to achieve :) In this case that would be using one template and grabbing the content from a data source of some description. The main reason being that this removes the content from the presentation and makes re-designs and updates much easier.


11:10 pm on Nov 5, 2003 (gmt 0)

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

mick, there was recently a discussion similar to this on this thread:


2:04 am on Nov 6, 2003 (gmt 0)

WebmasterWorld Administrator jatar_k is a WebmasterWorld Top Contributor of All Time 10+ Year Member

Welcome to WebmasterWorld mick shrimpton,

I guess everyone is forgetting their manners ;)

coopster linked to a very good thread.

I don't think it is, necessarily, a question of what is better. It depends on what works better for you mostly.

One thing I would say though. I try to keep all query strings out of my urls unless absolutely unavoidable. In your first example I would embed the section or pageid/pagename in the code.

include "template.php";

Most often I go with the second option. Include the header, content and then include the footer. I also usually maintain title/meta tags on each page so I can customize them for each one.


2:15 am on Nov 6, 2003 (gmt 0)

10+ Year Member

I would always go for "including" anything that is likely to be duplicated across my system.
Header and footer are usually (certainly on my sites) the same throughout, therefore I would always include header.php and footer.php.

This approach makes it very easy to change navigation (add another page to your system for example), or add tracking code to the footer.... many reasons I would take this approach.

Best regards

mick shrimpton

4:23 am on Nov 6, 2003 (gmt 0)

10+ Year Member

Thanks for the welcome and the advice.

Featured Threads

Hot Threads This Week

Hot Threads This Month