Logo         Community
The Company
Your Account
Contact Us
Injecting XML Content Into Page Templates With patXMLRenderer (part 1)
Create a modular Web site with templates, XML and Randy.

| Hard Sell |

patTemplate is a PHP-based template engine designed, in the author's words, to "help you separate program logic or content from layout". Developed by Stephan Schmidt, it is freely available for download and is packaged as a single PHP class which can be easily included in your application.

patTemplate assumes that a single Web application is made up of many smaller pieces - it calls these parts "templates" - and it provides an API to link templates together, and to fill them with data. A "template" is a text file containing both static elements (HTML code, ASCII text et al) and patTemplate variables. When patTemplate parses a template file, it replaces the variables within it with their values (a process referred to as "variable interpolation").

When using patTemplate, these values for template variables are usually defined by the developer at run-time, and may be either local to a particular template, or global across all the templates within an application. If you would instead prefer to produce your content in XML format and have it magically (and automatically) integrated into your template(s), then you need to also become familiar with patXMLRenderer, a rendering engine also developed by Stephan Schmidt which "transforms XML into HTML pages (or any other ASCII Format you like) using the patTemplate class".

patXMLRenderer parses one or more XML files or data streams, matches the data in the XML file to the variables in the template(s), and automatically performs variable interpolation. Very simply, patXMLRenderer works by reading the elements in an XML file and then placing the corresponding content into templates which share the same name. For commonly-accessed files, the rendering engine also includes a caching feature to speed up access, and a logger to track activity and generate access statistics.

Over the course of this article, I'll be showing you how to use both patTemplate and patXMLRenderer in conjunction with each other, to automatically populate a template with content from an XML data source. I'll assume here that you have a working Apache+PHP installation, and that you have downloaded and installed the latest versions of both patTemplate and patXMLRenderer from their home page at http://www.php-tools.de/

If you have prior knowledge of patTemplate (or any other template engine) it will help you grasp the following material faster...but if you don't, don't worry, because the next page contains a crash course on everything you need to know. Let's get going!

How to do Everything with PHP & MySQL
How to do Everything with PHP & MySQL, the best-selling book by Melonfire, explains how to take full advantage of PHP's built-in support for MySQL and link the results of database queries to Web pages. You'll get full details on PHP programming and MySQL database development, and then you'll learn to use these two cutting-edge technologies together. Easy-to-follow sample applications include a PHP online shopping cart, a MySQL order tracking system, and a PHP/MySQL news publishing system.

Read more, or grab your copy now!

previous page more like this  print this article  next page
In trog...
Logging With PHP
Building A Quick-And-Dirty PHP/MySQL Publishing System
Output Buffering With PHP
Date/Time Processing With PHP
Creating Web Calendars With The PEAR Calendar Class
In the hitg report...
Crime Scenes
Animal Attraction
Lord Of The Strings
In boombox...
Patience - George Michael
Think Tank - Blur
My Private Nation - Train
In colophon...
Hostage - Robert Crais
The Dead Heart - Douglas Kennedy
Right As Rain - George Pelecanos
In cut!...
American Chai
The Core
Find out how you can use this article on your own Web site!

Copyright © 1998-2018 Melonfire. All rights reserved
Terms and Conditions | Feedback