Syntax
Templates consists of blocks which can be nested or extended. Blocks are defined by open tag {% and closed by close tag %}. After open tag name of block must be defined. Block name must be uppercase alphanumeric word. Content of block is defined inside curly braces.
Example:
{% BLOCK {
This is content of a block named BLOCK.
{% SUB {
This is sub-block named SUB.
}%}
}%}
Blocks can be extended simply by replacing block name with parent template filename.
Example:
{% template.tpl {
{% BLOCK {
This content will override content of block named BLOCK from template file template.tpl
}%}
}%}
Inside blocks PHP tags can be included. It is recommended to use PHP alternative syntax for control structures for more readable code.
Example:{% LIST {
<? if ($list) : ?>
<ul>
<? foreach ($list as $item) : ?>
<li><?= $item; ?></li>
<? endforeach; ?>
</ul>
<? endif; ?>
}%}
Comments are enclosed by {%% and %%} tags.
Example:{%% This is one line comment! %%}
{%%
Comments
can be spreaded
over many lines.
%%} Base
- tpl_path (path) : Getter/setter function for templights base path
- tpl_load (file) : Wrapper function for loading template form file
- tpl_render (template, context) : Render template within specified context
- tpl_read (file) : Reads a template file - templates can be read only from path defined with tpl_path function
- tpl_token (code) : Creates list of tokens from template code
- tpl_parse (tokens, nodelist) : Parses tokens and creates list of string nodes. Blocks are parsed recursively
- tpl_tostring (template) : Convert list of nodes into string
Extra
- tpl_compile (code) : Wrapper function for creating template form template code
- tpl_extend (template, template2) : Extend template from another template
- tpl_extend_block (template, block_name, block) : This function is used for overriding content of specific template block
- tpl_dump (template, file) : Wrapper function for dumping template into a file
