Flexible Content Management System


Phoenix Template Rendering Engine Overview

Contributed by I'd like to thank Ne on Feb 11, 2003 - 02:20 AM

<font face="Verdana" size="3" color="#990000">What is a template
rendering engine?
</font><font face="Verdana" size=2>

A template rendering engine is the total separation (abstraction) of an
application business logic and rules from the content layer (output HTML, XHTML,
XML, PDF, etc.). </font>

<font face="Verdana" size=2>It includes dynamic variable substitutions
(replaces keywords or place holders with content), dynamic block substitutions
(for example the result of a record set from a query, for instance the number
of available news topics on the news index), amazing capabilities to process
unlimited nested loops among many others. </font>

<font face="Verdana" size=2>Conditional statements ( [if/elsif/else]
which allow you to make decisions based on user interaction in a easy to understand
way - optional). </font>

<font face="Verdana" size=2>The problem here is many template
solutions for PHP are based on regular expressions replacements, which highly
complicated the code and added an immense overhead into the application, this
regular expressions metaphor where hard to extend (and to adjust to taste),
and did not quite provided the complete separation of presentation and logic
(for example, to make rows of a table alternate colors, PHP code had to be adjusted).</font>

<font face="Verdana" size=2>Instead of following this route and
live with this and many other drawbacks, Phoenix takes advantage of a revolutionary
concept in template rendering engines, provided by the underlying architecture
of Smarty. The compilation of templates, which combines the speed of execution
of pure PHP code with the ease and simplicity of template syntax.</font>

<font face="Verdana" size=2>By using this approach template files
are first converted into PHP scripts before they are executed. This may sound
costly in terms of performance until you consider that this need only be done
when the template file is changed! Once a template file is compiled, they are
stored for later use (and re-use) using a caching mechanism, the end result
being a reduced overall server load. Which can be greatly enhanced (up to 500%)
by the use of PHP optimizing technologies like php-accelerator or the zend optimizer.</font>

<font face="Verdana" size=2>The second biggest advantage is extensibility,
this is what really makes it invaluable for programmers and designers a like.</font>

<font face="Verdana" size=2><font size="3" color="#990000">How
does it work?

</font><font size="3"> </font>
Basically templates work quite similar to
any ordinary HTML page, it uses template "tags" to distinguish dynamic content
(data provided from the DB for example), from the rest of the template which
is pure HTML. This tags are then automatically replaced with the result of the
requested data set. All template functions are loaded on demand this means that
even though the rendering engine is extensive in its core it will only load
the required code to perform each task.</font>

<font face="Verdana" size=2>While working with templates you have
access to a wealth of resources, among them are:</font>

<font face="Verdana" size=2>Variable modifiers (allows you to
transform on the fly the properties of your content, i.e. Caps, indentation,
upper, lower, etc) </font>

<font face="Verdana" size=2>Configurations files, this allow you
to define settings for colors, width and practically every aspect of the HTML

<font face="Verdana" size=2>A wealth of Built-in functions which
you can extend, like free block/module positioning, forms, automatic clocking
and encoding of email addresses, and many more.</font>

<font face="Verdana" size=2>You can easily add and extend with
your own functions the engine by taking advantage of the plugin architecture.</font>

<font face="Verdana" size=2>Many new possibilities arise with
the capability of automatic inclusion of static content either local or remote
on the fly.</font>

<font face="Verdana" size=2>Caching Mechanisms designed with great
granularity allows you to specify how, when and how often cached content is
to be updated (turning your site as fast as static HTML) and under which conditions.</font>

<font face="Verdana" size=2><font size="3" color="#990000">Advanced

<font face="Verdana" size=2>Prefilters

a set of functions that are run on the templates prior to them being compiled
with the engine. (i.e. removing unwanted comments form them)</font>

<font face="Verdana" size=2>PostFilters

This are functions that are executed after the templates have been compiled.

could help add valuable data to the whole of your templates if needed on the

<font face="Verdana" size=2>Output Filters

feature allows you to apply settings to content while being executed as opposed
to the postfilters which are applied just before saving the compiled template.</font>

<font face="Verdana" size=2>Multiple Template sources

may come from a variety of sources, like file system or the database.</font>

<font face="Verdana" size=2>Debugging Tools

debugging console which allows one to trace all items related to any and all
templates used diring the course of a page rendering.</font>

<font face="Verdana" size=2>The pnTemplate API

(Template Application Programming Interface) provides a set of tools that allow
programmers to harness the full set of combined resources that PostNuke and
Smarty provide.</font>

<font face="Verdana" size=2>It follows the pnAPI naming conventions
and style and will become easy to understand and apply for module/block programming,
taking current modules and block to the next level of usability, flexibility
and power.</font>

<font face="Verdana" size=2>The Phoenix Administration (system)

It’s the front end for all
this power and flexibility, it manages Themes, which are composed of templates,
that in turn have interesting properties like content type (html, xhtml, csv,
rss, pdf), they also belong to a layout, each template in a theme can belong
to a different layout, lets say you create a "dual column" layout and an "art
deco", layout for theme "Postnuke", then you can switch among this with the
click of a mouse, and then apply this system wide, templates also belonge to
specific zones (header, footer, module content, block etc.)</font>

<font face="Verdana" size=2>Templates install them self’s
similar to how modules do now, you just drop in the theme, initialize and activate
it and you are done. Same goes for upgrades or removal.</font>

<font face="Verdana" size=2>In the Phoenix administration module
you can manage all aspects of the rendering engine, including but not limiting
to all properties that control the behavior of smarty, as well as create, edit,
delete templates and its related itmes online, since you can choose to use file
system templates or db templates or a combination of both, you can directly
upload new sets of templates from your computer.</font>

<font face="Verdana" size=2>You have access to CSS and many more
properties and features, the best part of it all is, that you can have the old
themes right along with the next generation and also switch back and forth among
them with ease.</font>

<font face="Verdana" size=2>Templates Programming Language
and Active Zones

While working with templates
as mentioned before you can either use the basic template "tags" and normal
HTML or go beyond the choice is yours, the rendering engine provides enough
resources to make your templates intuitive and intelligent accomplishing quite
complex task with great ease, this is done by the use of what we call the "active
zones". Active zones are special place holder areas in your templates that allow
execution of commands from the template rendering language or invocation of
plugins, filters, variable substitution, etc.</font>

<font face="Verdana" size=2>This, active zones, are easy to use
and apply and will make your life very simple and productive while customizing
and designing the site of your dreams.</font>

<font face="Verdana" size=2>In conclusion the Phoenix Template
Rendering Engine
can answer the needs and requirements of both novices and
seasoned developers or graphics designer. And it supports popular HTML editors
like DreamWeaver among others allowing you to use visual tools to enhance your
experience and over-all productivity harnessing all this power in one simple

For reference if you happen to read this before the principal article of this series please read the first part which you will find here:

Note: [ For clarification 1st quarter refers to the 1st four (4) months [Jan-Apr] of 2003, thus the goal is to have the 0.8 release by the ends of april - 2003.]