PHP
  Home arrow PHP arrow Page 4 - Template-Based Web Development With patTemplate (part 1)
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Template-Based Web Development With patTemplate (part 1)
By: Team Melonfire, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 7
    2002-05-28


    Table of Contents:
  • Template-Based Web Development With patTemplate (part 1)
  • Hard Sell
  • Message In A Bottle
  • Slice And Dice
  • Music To Your Ears
  • Watching The Clock
  • A Bookworm In The Ointment
  • A Rose By Any Other Name...

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Template-Based Web Development With patTemplate (part 1) - Slice And Dice
    ( Page 4 of 8 )

    It's also possible to split a single page into smaller, modular templates, and link these templates together to create new and interesting shapes and patters. Take a look at how this might be accomplished:


    <!-- main page --> <patTemplate:tmpl name="main"> <patTemplate:link src="header" /> <patTemplate:link src="body" /> <patTemplate:link src="footer" /> </patTemplate:tmpl> <!-- page header --> <patTemplate:tmpl name="header"> <html> <head> <basefont face="Arial"> </head> <body bgcolor="navy" text="white" link="white" vlink="white" alink="white"> </patTemplate:tmpl> <!-- page body --> <patTemplate:tmpl name="body"> <center> Feelin' blue? How about a little <a href="http://www.melonfire.com/community/columns/boombox/">music</a>? </center> </patTemplate:tmpl> <!-- page footer --> <patTemplate:tmpl name="footer"> <p>&nbsp;<p align="right"> <font size="-2">{COPYRIGHT}</font> </body> </html> </patTemplate:tmpl>
    In this case, I have three different templates, one each for the page header, body and footer. I also have a fourth template, this one merely containing links to the remaining three templates. When patTemplate parses this container template, it will find and follow the links to the other templates, parse them and display them.

    Here's the script which does all the work:

    <?php // include the class include("include/patTemplate.php"); // initialize an object of the class $template = new patTemplate(); // set template location $template->setBasedir("templates"); // set name of template file $template->readTemplatesFromFile("music.tmpl"); // assign values to template variables $template->AddVar("footer", "COPYRIGHT", "This material copyright Melonfire, " . date("Y", mktime())); // parse and display the template $template->DisplayParsedTemplate("main"); ?>
    As you can see, it's almost identical to the one on the previous page - which only serves to demonstrate how transparent and simple the process of linking templates together is.

    Here's what the output looks like:



    If you have a Web page which consists of many individual pieces, you'll find this ability to create independent, modular templates immensely valuable - and once you start using it, you'll wonder how you ever worked without it!

     
     
    >>> More PHP Articles          >>> More By Team Melonfire, (c) Melonfire
     

       

    PHP ARTICLES

    - Using Directory Iterators to Build Loader Ap...
    - Using the spl_autoload() Functions to Build ...
    - Working Out of the Object Context to Build L...
    - Using the _autoload() Magic Function to Buil...
    - The Destruct Magic Function in PHP 5
    - The Autoload Magic Function in PHP 5
    - Developing a Recursive Loading Class for Loa...
    - The Sleep and Wakeup Magic Functions in PHP 5
    - Using the Clone Magic Function in PHP 5
    - Including Files Recursively with Loader Appl...
    - The Call Magic Function in PHP 5
    - Designing a Captcha System with PHP and MySQL
    - Using Static Methods to Build Loader Apps in...
    - The Isset and Unset Magic Functions in PHP 5
    - Advanced PHP Form Input Validation to Check ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT