A PHP-based template class inspired by the example at http://www.sitepoint.com/print/beyond-template-engine The idea is to simplify the template engine by just using regular old PHP source files as template files. Since the syntax for advanced templating is not significantly less complicated than regular PHP syntax, we might as well save ourselves some trouble and just use PHP.
Whether HTML helpers should output their data in addition to returning it. */
public function get( |
| ) |
Get a template var as a string.
var | (string) The variable name |
escape | (boolean) Whether/how to escape the data. |
Returns The var value, or empty string if it is not set.
public function raw( |
| ) |
Same as get(), but echoes rather than return.
public function put( |
| ) |
Same as get(), but echos rather than return and escapes HTML by default.
public function set( |
| ) |
Sets a template variable.
var | (string) The name of the variable. |
val | (mixed) Optional value for the variable. Defaults to true. |
The value passed or true.
public function unsetVar( |
| ) |
Unsets a previously set template variable.
var | (string) The name of the variable to unset. |
public function varSet( |
| ) |
Determine if a template variable has been set.
var | (string) The name of a template variable. |
True if var has been set, false otherwise.
public function reset( |
| ) |
Resets a template back to its empty state, clearing all variables and the file.
file | (string) An optional file name for the reset template. |
Gets the search path for templates. If a custom path list is set, it will return that. Otherwise, it will return the following paths, if applicable: - BLOG_ROOT/themes/THEME_NAME/templates - BLOG_ROOT/templates - USER_DATA_PATH/themes/THEME_NAME/templates - INSTALL_ROOT/themes/THEME_NAME/templates - INSTALL_ROOT/themes/default/templates
An array of path strings
public function block( |
| ) |
Defines a template block for future use. This is doen by associating a name with a function that outputs the desired markup.
name | (string) The name of the template block, normally of the form "filename.section", though this is not enforced. |
content_callback | (callable) A function that outputs the desired markup for this block. It takes one parameter, an array of values to inject into the template. |
public function showBlock( |
| ) |
Outputs a template block using the data set for this template. Note that the block must have been previously define. Note that this can be called inside a block definition to achieve block nesting.
name | (string) The name of the template block to output. |
The string returned by the block function, if any.
public function extends( |
| ) |
This declares that the current temlpate file extends one of the default theme template files. This allows you to override specific blocks in a default template without having to duplicate all the other code.
Note that this method should be called at the top of the template before any of the blocks are defined. If it isn't, you risk your blocks being clobbered by the default template.
template_name | (string) The name of the template to extend. |
theme | (string) The theme the template is in, "default" by default. |
public function process( |
| ) |
Process the template and get the output.
If the template is using blocks rather than plain-old PHP/HTML, then this method will look for a block named "main" and execute it if it is found.
return_results | (boolean) Determines whether the output should be returned in a string instead of sent straight to the client. Default is true. Returns: The output string if return_results is true. Otherwise, true on success and false on failure. |