Home arrow PHP arrow Developing an Extensible Template Processor in PHP 5

Developing an Extensible Template Processor in PHP 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.

TABLE OF CONTENTS:
  1. Developing an Extensible Template Processor in PHP 5
  2. Getting started: defining the basic structure of the template processor
  3. Assembling the template system: coding the "TemplateProcessor" class
  4. Coding the workhorse of the class: defining the "processTemplate()" method
  5. Getting the "TemplateProcessor" class completed: defining the remaining class methods
By: Alejandro Gervasio
Rating: starstarstarstarstar / 8
May 02, 2006

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

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
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: