PHP
  Home arrow PHP arrow Page 2 - Working with Multiple Template Files to Separate Logic from Presentation
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

Working with Multiple Template Files to Separate Logic from Presentation
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 9
    2006-05-16


    Table of Contents:
  • Working with Multiple Template Files to Separate Logic from Presentation
  • Setting up the basics of chunked caching: defining multiple template files
  • Parsing multiple template files: redefining the “TemplateProcessor” class
  • Putting the “TemplateProcessor” class to work: setting up a concrete example

  • 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


    Working with Multiple Template Files to Separate Logic from Presentation - Setting up the basics of chunked caching: defining multiple template files
    ( Page 2 of 4 )

    One of the most remarkable benefits of chunked caching systems rests on the ability to cache different sections of a web page, which can be treated as independent structures. This concept makes a lot of sense if you consider that most websites have different areas, such as headers and footers that don’t change very often, and evidently can take advantage of a caching mechanism.

    In this case, keeping in mind the fundamentals of a chunked caching system, I’m going to define three different template files, each of them corresponding to one particular section of a web page: header, body and footer respectively. Then, after defining all the template files, I’ll modify the signature for some methods of the “TemplateProcessor” class, so it can handle the templates as independent files, and eventually assign distinct cache expiration times to each of them, when their contents are cached.

    Here are the three basic template files that I plan to use in conjunction with the template processor class. First, the “header_template.htm” file:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>{title}</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-
    8859-1" />
    <link rel="stylesheet" type="text/css" href="style.css" />
    </head>
    <body>
    <div id="header">{header}</div>

    Next, you can see the definition of the “body_template.htm” file:

    <div id="content">{maincontent{staticdata}{dynamicdata}}</div>

    And finally, the signature of the “footer_template.htm” file:

    <div id="footer">{footer}</div>
    </body>
    </html>

    As you can see, I simply split a typical template file into three different areas, so they can be handled separately. Also, I kept their structure basic, thus you can easily understand how distinct template files will be parsed and then cached, in accordance with their time expiries.

    Now that you know how each template file looks, it’s time to move on and start coding the improved “TemplateProcessor” class. To see how this will be done, please click on the link below.



     
     
    >>> More PHP Articles          >>> More By Alejandro Gervasio
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





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