PHPTemplate
LnBlogObject
PHPTemplate

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.

Ihnerits

LnBlogObject

Properties
helper_output

Whether HTML helpers should output their data in addition to returning it. */

Functions
get
public function get(
$var,
$escape false
)

Get a template var as a string.

Parameter
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.

raw
public function raw(
$var,
$escape false
)

Same as get(), but echoes rather than return.

put
public function put(
$var,
$escape self::ESC_HTML
)

Same as get(), but echos rather than return and escapes HTML by default.

set
public function set(
$var,
$valtrue
)

Sets a template variable.

Parameters
var

(string) The name of the variable.

val

(mixed) Optional value for the variable.  Defaults to true.

Returns

The value passed or true.

unsetVar
public function unsetVar(
$var
)

Unsets a previously set template variable.

var

(string) The name of the variable to unset.

varSet
public function varSet(
$var
)

Determine if a template variable has been set.

Parameter
var

(string) The name of a template variable.

Returns

True if var has been set, false otherwise.

reset
public function reset(
$file""
)

Resets a template back to its empty state, clearing all variables and the file.

Parameters
file

(string) An optional file name for the reset template.

getSearchPath
public function getSearchPath()

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

Returns

An array of path strings

block
public function block(
$name,
$content_callback
)

Defines a template block for future use.  This is doen by associating a name with a function that outputs the desired markup.

Parameters
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.

showBlock
public function showBlock(
$name
)

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.

Parameters
name

(string) The name of the template block to output.

Returns

The string returned by the block function, if any.

extends
public function extends(
$template_name,
$theme 'default'
)

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.

Parameters
template_name

(string) The name of the template to extend.

theme

(string) The theme the template is in, "default" by default.

process
public function process(
$return_resultstrue
)

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.

Parameters
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.