Should you use includes to build site?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bradles
Forum Commoner
Posts: 89
Joined: Wed Jun 30, 2004 10:40 pm

Should you use includes to build site?

Post by bradles »

I'm designing my site that contains a header, navigation bar and footer that will be the same on each page. The only thing that will change will be the content.

Is it wise to design each page using includes: see my crude example below:

Code: Select all

<?php include 'header.php';?>
<?php include 'navigation.php';?>
<?php include 'contents1.php';?>
<?php include 'footer.php';?>
So you'd have a number of different contents pages that would load into the index page via your navigation. eg., contents1.php, contents2.php, contents3.php.

As I am still fairly new to php I just wanted to see if their is an ideal way to build a site without repeating too much code.

Any help would be greatly appreciated.

Brad.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

templating is an oft recommended design which I am fond of. If the page content repeats a lot, you can create a function that does the ~unique content addition, along with all the repetitive bits. I try to avoid including too much because of HD seeks required to load the pages.
bradles
Forum Commoner
Posts: 89
Joined: Wed Jun 30, 2004 10:40 pm

Post by bradles »

Thanks feyd,

How do you do templating? Is there a place you could recommend that will help get me started?

I must admit, a couple of times on my site i noticed it to be a bit slower than when I wasn't using PHP...I started to wonder if relying too much on PHP is a good thing? I want to keep my pages as quick as possible.

Brad.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

this may be of help :)
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

I am a fan of templates, too and it is really useful if you have similar pages in your site.
an advantage of it, if you have an error in your site you can change / fix it only in one page not in all pages..
(this is very important for me as a lazy programmer ;) )
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post by m3mn0n »

I love templating also.

Seperating presentation from processing is genius.

Some helpful research links:
[big_search]php templating tutorial[/big_search]
kaYak
Forum Commoner
Posts: 65
Joined: Mon Feb 02, 2004 2:43 pm
Location: USA

Post by kaYak »

You could use the Smarty template engine. That is what I use to build my sites with. You can find that at http://smarty.php.net. It is fairly easy to use. :)
User avatar
mudkicker
Forum Contributor
Posts: 479
Joined: Wed Jul 09, 2003 6:11 pm
Location: Istanbul, TR
Contact:

Post by mudkicker »

techguy wrote:You could use the Smarty template engine. That is what I use to build my sites with. You can find that at http://smarty.php.net. It is fairly easy to use. :)
is it useful even in very complicated php files?
i always stand away of smarty because of this..
what do you think?
Post Reply