Introduction
Introduction
HTML_Template_Flexy started it's life as a simplification of HTML_Template_Xipe, However the long term aim of Flexy is to provide a universal Template Base API for Compiling and native PHP type templates.
Flexy currently supports a number of backends (Template Formats), and is designed to be extended to support more, The Key Formats are:
Standard - A rich Tokenizer driven engine, that uses {variable_placeholders}, attribute based (flexy:foreach="...."), and custom tag <flexy:tojavascript ... To rapidly create PHP code from simple markup. These templates are designed to be editable in WYSIWYG HTML editors, without breaking the tags
Regex - A classic templating backend, for supporting Smarty, Xipe, or Email type convertion to PHP code.
Raw - A non compiling backend, that enables you to create templates using PHP, Useful if you intend to redistribute your application and are concerned about compilation
Data can be assigned in two ways with flexy, depending on your prefered style of working.
Push - you put data into the template engine, using $flexy->setData(), and $flexy->setDataByRef(), this is similar to the way Smarty and other templates work.
Push/Pull - You provide the outputer with a Data Provider Object, (either a Data Object, or a Controller) that contains the data to display (and objects with methods that can be called). This has the added benefit of making the Variables in the template documentable, using PEAR standards, eg. PHPDoc comments.
With all this Flexibility, it still manages to achieve
Very Lightweight Simple API, which easy to learn
In Normal operation very little code is actually loaded (so it's fast)
How does HTML_Template_Flexy differ from other template systems
If you look around you will see there are other template systems available in PHP, they generally fall into two categories, Replacement Systems, or PHP Code builders.
Replacement systems like HTML_Template_IT, FastTemplate, PhpLib Template tend to be slower at doing block and nested block type templates and involve alot of code to add each variable to the template.
Php Code builders like Flexy, Smarty, SimpleTemplate (now HTML_Template_Xipe) tend to be better at more complex templates, and can offer a better approach to extendability. (the long term aim of Flexy is to integrate support for all of these PHP Generator templates into a simple package)
The Standard Compiling Backend uses a Tokenizer, which offers the possiblities of using HTML tags and attributes to provide looping and conditionals, and make dynamic XML_Tree like elements of HTML Forms that can be manipulated in your code. (This conversion is only done once when the template compiles)
Typical use example
Flexy template is normally called from within a Controller Class (in the Model,View,Controller paragam). You just send HTML_Template_Flexy, the name of the template, and the object to output. - any variable you want printing out just has to be set in the object being used to ouput.
Пример 43-1. Typical usage example for HTML_Template_Flexy
|
Now the example template,
Пример 43-2. Example Template for HTML_Template_Flexy
|
And the output
Пример 43-3. Output of example for HTML_Template_Flexy
|
Пред. | Начало | След. |
HTML_Template_Flexy | Уровень выше | Configuration Options |