Basket
Your basket is empty.
PHP XTemplate is a cool templating engine for PHP.
XTemplate allows you to store your HTML code separately from your PHP code (as opposed to compiling your template into PHP as per Smarty etc.). It has many useful features such as nested blocks and various kinds of variable interpolation, and yet the code is very short and very optimized.
XTemplate has been around for several years, it is considered stable and mature and has been used in many projects, more information at www.phpxtemplate.org
Create a filename using alphanumuric characters and underscores, e.g.
templates/component/hello_world.html
<!-- BEGIN: content -->
<p>write your HTML code here</p>
<!-- END: content -->
Global variables can be parsed directly into the html without assigns, for example:
{_SERVER.HTTP_HOST}
{_SERVER.PHP_SELF}
{_SERVER.HTTP_USER_AGENT}
Associative arrays can be called like this:
{DATA.id}
{DATA.title|htmlspecialchars}
{DATA.created|strtotime|strftime('%c', %s)}
Example usage:
<div id="copyright">
<p>© {TIME|strftime('%Y', %s)} {CONFIGURATION.global.copyright}</p>
</div>
{tagname|my_callback_func(true, %s)} - tagname contents passed at %s point
{tagname|my_callback_func} - tagname contents passed as single argument
{tagname|first_callback|second_callback('#value', true, %s)|third_callback #Comment}
If you want quotes within your quoted strings, you'll need to escape them with \
{tagname|callback('I hope this won\'t break')
// Simple string modifiers
'strtoupper', 'strtolower', 'ucwords', 'ucfirst', 'strrev', 'str_word_count', 'strlen',
// String replacement modifiers
'str_replace', 'str_ireplace', 'preg_replace', 'strip_tags', 'stripcslashes', 'stripslashes', 'substr',
'str_pad', 'str_repeat', 'strtr', 'trim', 'ltrim', 'rtrim', 'nl2br', 'wordwrap', 'printf', 'sprintf',
'addslashes', 'addcslashes',
// Encoding / decoding modifiers
'htmlentities', 'html_entity_decode', 'htmlspecialchars', 'htmlspecialchars_decode',
'urlencode', 'urldecode','xmlentities','html2text',
// Date / time modifiers
'date', 'idate', 'strtotime', 'strftime', 'getdate', 'gettimeofday',
// Number modifiers
'number_format', 'money_format',
// Miscellaneous modifiers
'var_dump', 'print_r'
Common XTemplate syntax is:
{FILE "component/fortunes.html"}
But we have extended this facility to use whole components:
{ONXSHOP_REQUEST_uniqueid #component/fortunes}
<!-- BEGIN: item -->{ITEM.title|htmlspecialchars}<br /><!-- END: item -->
Please go to github/laposa/templates
Please note that most of templates have their associated controller (PHP code).
In HTML use always double quotes. This is important for security, especially in forms input fields, value attribute. In Javascript single quotes, so you can write inline HTML using double quotes.
You cannot include PHP functions directly in your templates, however using the variable callback feature might be what you're looking for: e.g. {myvariable|mycallfunction}