Welcome to WebmasterWorld Guest from 54.146.201.80

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.

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

New User

10+ Year Member

joined:Oct 4, 2003
posts:2
votes: 0


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)

Junior Member

10+ Year Member

joined:Feb 26, 2003
posts:50
votes: 0


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)

Administrator

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

joined:July 31, 2003
posts:12533
votes: 0


mick, there was recently a discussion similar to this on this thread:
[webmasterworld.com...]
2:04 am on Nov 6, 2003 (gmt 0)

Administrator

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

joined:July 24, 2001
posts:15755
votes: 0


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.

$content=thispage;
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)

Preferred Member

10+ Year Member

joined:Sept 29, 2002
posts:356
votes: 0


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
Shady

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

New User

10+ Year Member

joined:Oct 4, 2003
posts:2
votes: 0


Thanks for the welcome and the advice.