This example shows using tag callbacks to call php functions or methods.
In this example we use the default text "Some text for example"
- Standard tags look like {tagname} or {tagarray.indexname} for arrays
- Tags with comments look like {tagname# Comment} or {tagname # Comment}
- Tags with callbacks look like {tagname|function} (using vertical bar or pipe symbol)
- They can all be combined {tagarray.indexname|function#Comment}
- Simple callback {example1|strtoupper}: {{example1|strtoupper}}
- Simple callback (same tag different callback) {example1|strtolower}: {{example1|strtolower}}
- Chained callbacks {example2|strtolower|ucwords}: {{example2|strtolower|ucwords}}
- Multi-parameter callback {example3|str_replace('Some', 'Replaced', %s)}: {{example3|str_replace('Some', 'Replaced', %s)}}
- Subclassed method callback {example4|my_custom_callback}: {{example4|my_custom_callback}}
- Taking things to the limit {example5|strtolower|ucwords|str_replace('Some', 'Replaced', %s)|my_custom_callback}: {{example5|strtolower|ucwords|str_replace('Some', 'Replaced', %s)|my_custom_callback}}
Any methods you create in a sub-class of XTemplate (e.g. my_class extends XTemplate) are automatically available as a callback and will take priority over function calls of the same name.
Additionally, the following callback functions are available as standard (can be altered in XTemplate::allowed_callbacks array):
{{callback}},