Home » HTML » HTML_Template_Sigma
An implementation of Integrated Templates API with template 'compilation' added
Download latest release 1.4.0 (there might be newer Composer installable version)
License: PHP License
Description
HTML_Template_Sigma implements Integrated Templates API designed by Ulf Wendel.
Features:
* Nested blocks. Nesting is controlled by the engine.
* Ability to include files from within template: <!-- INCLUDE -->
* Automatic removal of empty blocks and unknown variables (methods to manually tweak/override this are also available)
* Methods for runtime addition and replacement of blocks in templates
* Ability to insert simple function calls into templates: func_uppercase('Hello world!') and to define callback functions for these
* 'Compiled' templates: the engine has to parse a template file using regular expressions to find all the blocks and variable placeholders. This is a very "expensive" operation and is an overkill to do on every page request: templates seldom change on production websites. Thus this feature: an internal representation of the template structure is saved into a file and this file gets loaded instead of the source one on subsequent requests (unless the source changes)
* PHPUnit-based tests to define correct behaviour
* Usage examples for most of the features are available, look in the docs/ directory
Documentation
Maintainers
- Alexey Borzov (avb) — lead, active
Dependencies
Required
- PHP (>= 5.6.0)
- PEAR Installer (>= 1.10.0)
- ctype (extension)
Releases
- 1.4.0 (stable, 2025-10-31)
Release notes
License: PHP License
* Added a proper __construct() method (see bug #20967, bug #23751)
* Fixed examples to run on recent PHP versions
* Unit tests are run on PHP 5.6 to PHP 8.4 thanks to PHPUnit Polyfills package,
continuos integration is enabled on GitHub.
* It is possible to throw an instance of HTML_Template_Sigma_Exception
instead of returning PEAR_Error in case of error, this is enabled by
setting an 'exceptions' option to true: $tpl->setOption('exceptions', true);
This is disabled by default.
* Minimum required PHP version is now 5.6 - 1.3.0 (stable, 2014-01-13)
Release notes
License: PHP License
* Implemented a more robust cache writing algorithm, this should prevent
writing empty cache files and reading incomplete ones (bug #19220)
* Got rid of deprecated 'e' modifier for preg_replace(),
preg_replace_callback() is now used instead (bug #20068)
* Fixed built-in 'j' callback to allow using escaped strings in inline JS* Updated code to better conform to PEAR coding standards
* Updated code and tests to generate fewer errors under PHP5
* The minimum PHP version is now 4.3.0, as file_get_contents() is used - 1.2.0 (stable, 2008-07-22)
Release notes
License: PHP License
Changed unit tests to use current PHPUnit from http://www.phpunit.de/ rather
than old unsupported one from http://pear.php.net/Implemented parts of request #12221 (thanks to Carsten Wiedmann for ideas and
their initial implementation)
* It is now possible to add comments to the template file that are removed
from output: <!-- COMMENT --> ... <!-- /COMMENT -->
* Added new builtin callbacks 'e' and 'r' for htmlentities() and
rawurlencode(), respectively
* Added the 'charset' option for builtin 'h' and 'e' callbacks - 1.1.6 (stable, 2007-05-19)
Release notes
License: PHP License
Migrate to package.xml version 2.0, use proper header comment blocks.
Minor fixes to phpdoc comments, no code changes since previous release. - 1.1.5 (stable, 2006-05-31)
Release notes
License: PHP License
Fixed bug #6346: typo in _buildFunctionList()
Fixed bug #6902: correctly handle drive letters and path separators on Windows
Fixed bug #6905: use 'b' modifier for fopen() to prevent problems with cached templates on Windows
Calling setCacheRoot() with an empty argument will now disable caching. It was impossible
to disable it with previous behaviour.Added possibility to pass arrays as second arguments to setVariable() and setGlobalVariable(),
this will assign values to placeholders of the form {varName.arrayKey} in the template.
Thanks to Franz Pentenrieder <franz at quox.net> for idea and original implementation. - 1.1.4 (stable, 2005-11-05)
Release notes
License: PHP License
Fixed bug #5168: Prevent problems with template functions in included files
- 1.1.3 (stable, 2005-08-09)
Release notes
License: PHP License
* Fixed bug #4896 (loading a zero-length template file caused a warning)
* Fixed bug #5012 (placeholder delimiters were hardcoded in several places,
which prevented using custom delimiters) - 1.1.2 (stable, 2004-10-20)
Release notes
License: PHP License
Changed the code for parsing template function arguments. It will
now correctly unescape the escaped quotes within quoted arguments
(see bug #1840).
The new code throws errors on bogus arguments. If you previously
relied on undocumented behaviour of argument parsing method, your
code may break: test before upgrading. - 1.1.1 (stable, 2004-05-31)
Release notes
License: PHP License
Callbacks are not called if the block containing them is empty. Thanks
to Sergey Vasiliev for the suggestion. - 1.1.0 (stable, 2004-04-14)
Release notes
License: PHP License
* Fixed #876 (get_class() and get_class_methods() usage with PHP5)
Unit tests run on PHP5, all tests pass.
* Added clearVariables() method (see also #939)
* Added shorthand syntax for callbacks: {var:callback} instead of
func_callback({var})
* Added builtin callbacks
'h' for htmlspecialchars()
'u' for urlencode()
'j' to escape the string for usage in JavascriptThis release is dedicated to Lukas Smith
- 1.0.2 (stable, 2003-10-02)
Release notes
License: PHP License
* Removed _callbackExists() method, is_callable() is used instead
* Check for SIGMA_OK instead of PEAR::isError() where possible
* Fixed unit tests packaging. Should work OK in PEAR installation - 1.0.1 (stable, 2003-05-20)
Release notes
License: PHP License
* Added getBlockList() and getPlaceholderList() methods (thanks to Markus Wolff for the idea).
* HTML_Template_IT compatibility: get() does not clear the parsed block contents by default.
* Removed obsolete docs, current ones are in the PEAR manual. - 1.0 (stable, 2003-04-28)
Release notes
License: PHP License
This release has Sigma's template functions/callbacks infrastructure significantly enhanced.
This unfortunately means some backwards compatibility breaks. If you were using callbacks before, please carefully examine the release notes and test you scripts before upgrading to 1.0.
If you weren't using callbacks due to their shortcomings it is a good time to give them a try, consult docs/example_4.php for some of their possible applications.Template functions/callbacks changes and incompatibilities:
* Templates are parsed for function calls not only on setTemplate()/loadTemplatefile(), but on addBlock()/addBlockfile() and replaceBlock()/replaceBlockfile() as well.
* The arguments to template functions can now contain variable placeholders: func_uppercase('Hello, {username}!').
* Template functions are now compatible with template caching.
* Method setCallbackFunction() now accepts a callback that is compatible with call_user_func() as its second argument. Its third argument is used to control variable substitution in function arguments.
* Method performCallback() was removed. Callbacks are now called automatically when the block containing them is parse()'d.
* Callbacks are now called via call_user_func_array() instead of call_user_func(). This makes it possible to use built-in functions as callbacks, but also means that you have to rewrite your old functions!
* Usage example is available in docs/example_4.phpOther changes:
* Option 'use_preg' was removed.
* Stricter error checking when doing addBlockfile() with a prepared template. - 0.9.2 (stable, 2003-04-21)
Release notes
License: PHP License
* Added usage examples
* Added the cache FAQ
* This is the last 0.9.x release unless some bugs are found. The 1.0 release will
have callbacks significantly redone and will require changes to your scripts if
you use callbacks. - 0.9.1 (stable, 2003-04-18)
Release notes
License: PHP License
* Fix: if source template does not exist, do not load the 'prepared' one, throw an error instead.
Thanks to Maxim Panasiuk for the report. - 0.9 (stable, 2003-04-04)
Release notes
License: PHP License
Initial PEAR release
Bugs
| ID | Status | Type | Version | Date | Summary |
|---|---|---|---|---|---|
| #818 | Bogus | Bug | 2004-02-21 | No parsing with replaceBlockFile() | |
| #876 | Closed | Bug | 2004-02-26 | PEAR QA: improvement for get_class()-usage | |
| #939 | Bogus | Bug | 2004-03-03 | Wrong replacement for omit variables | |
| #1489 | Bogus | Bug | 2004-05-24 | text enclosed in {} vanishes | |
| #1653 | Wont fix | Req | 2004-06-16 | Callbacks in blocks with remove unknown | |
| #1840 | Closed | Bug | 2004-07-10 | stripslashes needed in _buildFunctionlist() | |
| #2604 | Bogus | Req | 2004-10-24 | looped blocks | |
| #2620 | Wont fix | Req | 2004-10-26 | HTML_Template_Sigma::get(), additional param | |
| #4896 | Closed | Bug | 2005-07-23 | Error if template file is empty | |
| #5012 | Closed | Bug | 2005-08-05 | Change of openingDelimiter and closingDelimiter | |
| #5168 | Closed | Bug | 2005-08-21 | Functions inside includes sometimes get »forgotten« | |
| #5359 | Bogus | Bug | 2005-09-11 | replaceBlockfile produces error | |
| #6204 | Bogus | Bug | 2005-12-09 | php5 and Special Characters | |
| #6346 | Closed | Bug | 2005-12-24 | Typo in Line 1711 | |
| #6824 | Bogus | Bug | 1.1.4 | 2006-02-17 | cache functionality strips mulitple linefeeds |
| #6902 | Closed | Bug | 1.1.4 | 2006-02-23 | Problem w/ cache filename on Windows |
| #6905 | Closed | Bug | 1.1.4 | 2006-02-23 | _getCache() function return false |
| #6908 | Wont fix | Bug | 1.1.4 | 2006-02-23 | variable value NULL & callback function |
| #6958 | Wont fix | Req | 1.1.4 | 2006-02-28 | Miss error message with call of loadTemplateFile(' ') |
| #8219 | Suspended | Req | CVS | 2006-07-14 | Remove line breaks after block tags |
| #8669 | Bogus | Bug | 1.1.5 | 2006-09-10 | Sets variable required to show a block |
| #10566 | Bogus | Req | 1.1.5 | 2007-03-30 | Change trim_on_save behaviour |
| #12221 | Closed | Req | 1.1.6 | 2007-10-11 | template comments, a new option 'charset' and 2 new buildin functions |
| #13379 | Closed | Doc | 1.1.6 | 2008-03-12 | INCLUDE directive ignored when using setTemplate |
| #14691 | Closed | Doc | 2008-09-22 | User note that is a documentation problem | |
| #18147 | Closed | Doc | 1.2.0 | 2010-12-27 | Wrong regex in variablenameRegExp |
| #19220 | Closed | Bug | 1.2.0 | 2012-01-13 | Empty cache files are not ignored |
| #20068 | Closed | Bug | 1.2.0 | 2013-09-19 | Deprecated: preg_replace() |
| #20967 | Closed | Req | 1.3.0 | 2015-10-16 | use __construct() constructor |
| #23751 | Closed | Req | 1.3.0 | 2018-05-21 | Provide valid constructor for HTML_Template_Sigma |