PHP
  Home arrow PHP arrow Developing an Extensible Template Proc...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
Moblin 
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: 4 stars4 stars4 stars4 stars4 stars / 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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!

    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


       · In this first article, you'll learn how to build the structure of the template...
     

       

    PHP ARTICLES

    - Handling Attachments in MIME Email with PHP
    - Completing the Project Management Application
    - Sending MIME Email with PHP
    - Handling Files for a Project Management Appl...
    - Viewing and Editing Tasks for a Project Mana...
    - More on Private Methods with PHP 5 Member Vi...
    - Adding Tasks to a Project Management Applica...
    - Utilizing Private Methods with PHP 5 and Mem...
    - Making Changes in a Project Management Appli...
    - Defining Public and Protected Methods with M...
    - HTML for a Project Management Application
    - Using Subclasses and Accessors with Member V...
    - Implementing Internet Protocols with PHP
    - Project Management: The Application
    - Working with Private Properties to Protect P...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway