--------------------------------------------------------------------------
##
##
--------------------------------------------------------------------------
MAIN
ExtensibleTemplate is a class designed to process template file, which are more HTML-compliant than Smarty, just to give an
example. All template tags are in the form <tpl:TAG param1="value1" param2="value2" ... paramN="valueN">...block...</tpl:tag> or
in case of the single tags, <tpl:TAG param1="value1" param2="value2" ... paramN="valueN" />
Is extensible because you can extend the class, and by creating specificly formed methods in the descendant class, you can add
new tags to the system. It will have a plug-in system as Smart has, but it'll take me some time.
Natively, the class has only 1 block tag and 4 simple tag defined.
--------------------------------------------------------------------------
##
##
--------------------------------------------------------------------------
LICENSING AND MISCELANEOUS.
You can use this class wherever you want to, free of charges. However, if you find it useful, and want to allow further
developing, you can contact me for donating instructions. Please use the PHPClasses.org mechanisms to contact me
I want to say, although I think is not needed, that you can contact me for ANY THING you need to... such as asking a question or
give a critic. It would be very useful to oknow your thoughs about this class
Well... I've done a hell of a job writing this file... I find too difficult to do such a thing. I don't like to, but well... I
know I MUST do that
Please, feel free to write me your impressions about this one
Cheers,
Daniel
--------------------------------------------------------------------------
##
##
--------------------------------------------------------------------------
DOCUMENTATION
NATIVE TAGS
The block tag is
<tpl:foreach control="variable_array" item="item_variable">
...
...
HTML BLOCK
..
...
</tpl:foreach>
where CONTROL is an array of associative array, where each value is a variable accesible by {item_variable.key}
--------------------------------------------------------------------------
Simple tags are:
<tpl:htmlselect NAME="htmlname" OPTIONS="array_of_options" [(ONCLICK|ONCHANGE|ONBLUR)="event"] [MULTIPLE=""] [CLASS="classname"] [ID="id"] [SIZE="size"] />
Generates a <select></select> tag
"array_of_options" is an array where each item is an associative array with the following keys:
VALUE => the item value
TEXT => The text to be shown
SELECTED => if the item is selected.
-------
<tpl:htmlradio NAME="htmlname" OPTIONS="array_of_options" [CLASS="classname"] [ID="id"] />
Generates radio buttons
"array_of_options" is an array where each item is an associative array with the following keys:
VALUE => the item value
TEXT => The text to be shown
CHECKED => if the item is checked.
-------
<tpl:htmlcheck NAME="htmlname" OPTIONS="array_of_options" [CLASS="classname"] [ID="id"] />
Generates check boxes
"array_of_options" is an array where each item is an associative array with the following keys:
VALUE => the item value
TEXT => The text to be shown
CHECKED => if the item is checked.
--------
<tpl:include FILE="filename" [DIR="parent_path_for_file"] />
Includes a new template inside the processed one.
##############################
Besides tags, you can also use special functions. Special functions are intended to use inside html tag parameters, for example
when you need to evaluate a math expression to set the color parameter for the <font> tag.
Special functions are called as follow:
<[tpl:]tag parameter="#function_name param1=value1 param2=value2 param3=value3 paramN=valueN #"
Please note that trailing space before the closing # is required.
To define a special function in your descendant class, you just need to write a method named sf_YOURFUNCTION
To define a block tag, write a method named bt_YOURTAG
and for a simple tag, write a method named tg_YOURTAG
Every method related tag must be defined as follows:
BLOCK TAGS
----------
public function bt_YOURTAG($parameters="",$blockcode,$vars) { ... }
$parameters will be filled by the parent class with the parameters defined in <tpl:yourtag param1="val1" paramN="valN">...</tpl:yourTag>
(different case in tag name in the above example is intentional, you can use any casing you choose)
$blockcode will be filled by the template engine with the enclosed html block
and finally
$vars will have the variables to be accesible from the block
SIMPLE TAGS
-----------
public function tg_YOURTAG($parameters="", $variables="") { ... }
$parameters will be filled by the parent class with the parameters defined in <tpl:yourtag param1="val1" paramN="valN" />
$variables will have the variables to be accesible from the block
SPECIAL FUNCTIONS
-----------------
public function sf_YOURFUNCTION($parameters="", $variables="") { ... }
$parameters will be filled by the parent class with the parameters defined in <tpl:yourtag param1="val1" paramN="valN" /º>
$variables will have the variables to be accesible from the block
--------------------------------------------------------------------------
##
##
--------------------------------------------------------------------------
PUBLIC METHODS REFERENCE:
setTemplateDir($path)
Sets the top folder for processing templates
--------------------------------------------------------------------------
SetValue($variable,$value,$sanitized)
Sets a template variable to the given value. $sanitized is an optional boolean parameter that means that the value will be
processed for latin languages accented characters, replacing them with HTML compliant codes
--------------------------------------------------------------------------
ProcessFile($templateFile,$vars)
Process the given template file, which MST reside in the templateDir hierarchy of folders. If $vars parameters is provided, the
tempate will be processed with THOSE variables defined, in the form of array("VARIABLE"=>"VALUE). if not, the assigned variables
with setValue will be used
I encourage you to write your own descendant class to add your tags, rather than modifying the native one, because updating would
be a little dangerous. You could loose ALL your own tags!
|