PHP
  Home arrow PHP arrow Developing an Extensible Template Processor in PHP 5
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

Developing an Extensible Template Processor in PHP 5
By: Alejandro Gervasio
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 8
    2006-05-02


    Table of Contents:
  • Developing an Extensible Template Processor in PHP 5
  • Getting started: defining the basic structure of the template processor
  • Assembling the template system: coding the "TemplateProcessor" class
  • Coding the workhorse of the class: defining the "processTemplate()" method
  • Getting the "TemplateProcessor" class completed: defining the remaining class methods

  • 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


    Developing an Extensible Template Processor in PHP 5
    ( Page 1 of 5 )

    This is the first part of a three-part series that covers separating logic from presentation in PHP applications. In this article you will learn to develop a template system that is advanced enough to meet the requirements of a majority of applications.
    A downloadable file for this article is available here.

    Introduction

    In consonance with the evolution of PHP to the mature multi-purpose programming language that you see today, template systems have largely grown in popularity, due to their ability to separate the driving logic of an application from its visual presentation.

    Definitely, splitting your PHP applications into different sections or layers, which are conceived in most of cases as the data, the application and the presentational layers respectively, helps to make the entire program more flexible and maintainable. In general terms, when you use a template system to keep the application's logic isolated from the visual appearance, usually you're going to work with one (or many) template files that contain a specific number of placeholders, which will be filled with real data.

    As you probably know, replacing placeholders with actual data (coming either from database tables, flat files or other sources) is the responsibility of the application layer, which implements the required "smart" logic that substitutes data markers with real content. Taking into account  the basic functionality provided by most PHP template systems, you can pick up a particular software package in accordance with the size and complexity of the application that you're currently developing, and of course in consonance with your own expectations.

    Particularly when it comes to choosing a specific template system, you'll find a plethora of options, ranging from basic placeholders replacing libraries, to full-featured systems like the popular Smarty, which eventually might require learning proprietary template statements, in order to get the most out of it.

    Nevertheless, it's possible to develop an intermediate template system that meets the requirements of a vast majority of applications, without the need to appeal to basic packages or having to deal with the numerous features of Smarty. It's precisely for this reason that this series will be focused on developing an extensible template processor in PHP 5. The template system that I plan to build will expose a handy set of features, which hopefully will satisfy the most common requirements of modern template software, without the need to learn a new "template-oriented" sub language.

    Are you ready to learn how to code an expandable PHP 5 template processor? Right, let's get started.



     
     
    >>> 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