Introduction - template syntax
Placeholders
The default format of placeholder is
{[0-9A-Za-z_-]+} |
Actual values for the placeholders are set using setVariable() and setGlobalVariable() methods. Placeholders for which no values were set are removed from output by default.
Blocks
The format of a block is
<!-- BEGIN [0-9A-Za-z_-]+ --> ... block content ... <!-- END [0-9A-Za-z_-]+ --> |
The nesting of blocks is permitted, but be careful while parsing. You have to parse() the innermost block first and then go from inner to outer.
In Sigma the whole template itself is treated as a virtual block called "__global__". Most block-related functions use this block name as default.
<!-- INCLUDE --> statements
It is possible to include a template file from within another template file using an <!-- INCLUDE filename --> statement:
... some content ... <!-- INCLUDE filename.html --> ... some more content ... |
Some things to note:
Although this functionality is implemented using addBlockfile(), unlike addBlockfile() no new blocks are created in the template.
<!-- INCLUDE --> calls are processed before any variable substitution can take place. So <!-- INCLUDE {placeholder} --> will not work unless you actually have a file named {placeholder} and want to load it.
Template functions
Sigma templates can contain simple function calls. This means that the author of the template can add a special placeholder to it
... some content ... func_h1("embedded in h1") ... some more content ... |
Format of such function name is as follows
func_[_a-zA-Z]+[A-Za-z_0-9]* |
func_translate('Hello, {username}') |
Quoting of template function arguments
Замечание: The information in this section applies to HTML_Template_Sigma version 1.1.2 and later, please upgrade if you have problems with template function arguments in previous versions.
Quoting of function arguments is not mandatory, the following is a perfectly valid template function:
func_uppercase(Some unquoted text) |
The next thing to consider is that HTML_Template_Sigma is mostly targeted for generating HTML. Therefore a quoted string within an argument is most probably a tag attribute. The contents of such strings are not parsed for commas and parentheses. Therefore the following is also a perfectly valid template function:
func_foo(<a href="javascript:foo(bar, baz)">Do foo</a>) |
Finally, the argument should be quoted if it is an empty string or if its leading or trailing whitespace is significant (leading and trailing whitespace will be removed from unquoted arguments).
The arguments can be quoted using either single or double quotes. If an argument contains a quote of the same type, then it should be escaped using the backslash symbol '\'. The backslash symbol itself should also be escaped,
func_foo('O\'really') func_foo('AC\\DC') |
Пример 43-1. Valid and invalid template function arguments
|
Shorthand for template functions
Since release 1.1.0, instead of using
func_callback({var}) |
{var:callback} |
'h' for htmlspecialchars()
'u' for urlencode()
'j' for a method of Sigma that escapes the string for usage in Javascript string constants.
Thus, if you add {var:h} placeholder to the template, var will be have unsafe characters replaced by corresponding HTML entitites.
Usage Example
Other usage examples: There are several usage examples in the package archive that cover most of its functionality. You are encouraged to review them along with the docs.
Пример 43-2. The table.html template file
|
Пример 43-3. The table_header.html template file
|
Пример 43-4. The script
|
Пример 43-5. The output
|
Пред. | Начало | След. |
HTML_Template_Sigma | Уровень выше | Introduction - cache |