PTE - Page 4
This is all well and good when we're talking about templates for bits and pieces of pages. But what about the main site template, or main templates for major sections of sites?
I'm glad you asked. My approach to this, and so far, on small to medium sized web sites it has been very successful, is to create several main includable files. The web site you're reading this article on utilizes this approach. For the overall design of a site, I will create two, sometimes three include files. There wouldn't be any reason why you couldn't create even more, but the number should stay under 5 so it remains manageable.
I create header.php, footer.php, and depending on the design, I sometimes create a sidebar.php. On pages where we need to generate the entire page, I will set some variables, then include header.php. For example...
<?php $title = 'Using PHP as Your Template Engine - Page 2'; $breadCrumbs['Home'] = '/'; $breadCrumbs['Articles'] = '/articles/'; $breadCrumbs['Using PHP as Your Template Engine'] = '/articles/pte.php'; $breadCrumbs['Page 2'] = ''; include ( '../header.php' ); ?>
After including the header, I sometimes escape back to html, or, if the page requires it, I will use some PHP code to generate content from the database or from memory structures. On these article pages, I simply type in the article text and html markup for them. On my product pages I use memory structures to automatically generate the page.
For sample code, I will take the last little bit of the first page of this article. This next block is how I finish the page.
<a href="pte2.php">Continue Reading on Page 2</a> <?php include ( '../footer.php' ); ?>
So, putting it all together, the page looks something like this.
<?php $title = 'Using PHP as Your Template Engine - Page 2'; $breadCrumbs['Home'] = '/'; $breadCrumbs['Articles'] = '/articles/'; $breadCrumbs['Using PHP as Your Template Engine'] = '/articles/pte.php'; $breadCrumbs['Page 2'] = ''; include ( '../header.php' ); ?> Article Goes Here... <a href="pte2.php">Continue Reading on Page 2</a> <?php include ( '../footer.php' ); ?>
But could just as easily look something like:
<?php $article = new TArticle( $_POST['AID'], $_POST['PAGE'] ); $article->fetch(); $article->doBreadCrumb( $breadCrumbs ); extract( $article->getTemplateVars() ); include( 'header.php' ); echo $articleText; // available because of our call to extract // OR echo $article->text; include ( 'footer.php' ); ?>
Continue Reading on Page 5
Jump to page: _1_ | _2_ | _3_ | _4_ | _5_ | _6_
Thank you for reading! Feedback may be left by using the contact form
Interesting and/or informative comments will be posted on the article comment page.
For web site hosting I recommend - www.bluehost.com

Others have spoken of Tim's technical expertise in PHP and MySQL, but the main thing that sets him apart from any other programmer I've worked with is he tries to get a deep understanding of my overall needs and business requirements.