appendvoid append(mixed $key)void append(string $key, mixed $value[, bool merge])
EXAMPLE
=============================
// passing key/value pairs
$tpl->append("Name", "Fred");
$tpl->append("Address", $address);
// passing an associative array
$tpl->append(array("Name" => "Fred", "Address" => $address));
append_by_refvoid append_by_ref(mixed $key)void append_by_ref(string $key, mixed $value[, bool merge])
EXAMPLE
=============================
// passing key/value pairs
$tpl->append_by_ref("Name", "Fred");
$tpl->append_by_ref("Address", $address);
// passing an associative array
$myarray = array("Name" => "Fred", "Address" => $address)
$tpl->append_by_ref($myarray);
assignvoid assign(mixed $key)void assign(string $key, mixed $value)
EXAMPLE
=============================
// passing key/value pairs
$tpl->assign("Name", "Fred");
$tpl->assign("Address", $address);
// passing an associative array
$tpl->assign(array("Name" => "Fred", "Address" => $address));
assign_by_refvoid assign_by_ref(mixed $key)void assign_by_ref(string $key, mixed $value)
EXAMPLE
=============================
// passing key/value pairs
$tpl->assign_by_ref("Name", "Fred");
$tpl->assign_by_ref("Address", $address);
// passing an associative array
$myarray = array("Name" => "Fred", "Address" => $address)
$tpl->assign_by_ref($myarray);
assign_configvoid assign_config(string $key)void assign_config(string $key, mixed $value)
assign.
EXAMPLE
=============================
// passing key/value pairs
$tpl->assign("Name", "Fred");
$tpl->assign("Address, $address);
// passing an associative array
$tpl->assign(array("Name" => "Fred", "Address" => $address));
clear_assignvoid clear_assign([string $key])void clear_assign([array $key])
EXAMPLE
=============================
// clear a single variable
$tpl->clear_assign("Name");
// clear a multiple variables
$tpl->clear_assign(array("Name", "Address));
// clear all variables
$tpl->clear_assign();
clear_all_assignvoid clear_all_assign()
EXAMPLE ============================= // clear a single variable $tpl->clear_all_assign();
clear_configvoid clear_config([string $key])
EXAMPLE
=============================
// clear a single variable
$tpl->clear_config("Name");
// clear a multiple variables
$tpl->clear_config(array("Name", "Address));
// clear all variables
$tpl->clear_config();
get_template_varsmixed get_template_vars([string $key])
$key. This will not return variables assigned inside the template, unless the template has already been processed.
EXAMPLE
=============================
// get the template variable called 'foo'
$foo = $tpl->get_template_vars('foo');
// get all assigned template variables
$tpl_vars = $tpl->get_template_vars();
get_vars_configmixed get_vars_config([string $key])
$key. This will not return values loaded by config_load calls embedded in a template, unless the template has already been processed.
EXAMPLE
=============================
// get the template variable called 'foo'
$foo = $tpl->get_vars_config('foo');
// get all assigned template variables
$tpl_vars = $tpl->get_vars_config();
clear_compiled_tplvoid clear_compiled_tpl([string $file])
EXAMPLE
=============================
// clear all compiled files
$tpl->clear_compiled_tpl();
// clear the compiled file for the file called "index.tpl"
$tpl->clear_compiled_tpl("index.tpl");
clear_cachevoid clear_cache([string $file [, string $cache_id]])
EXAMPLE
=============================
// clear the whole cache
$tpl->clear_cache();
// clear all files in the "gallery" group, such as "gallery|view" and "gallery|thumbnail"
$tpl->clear_cache(null, "gallery");
// clear only the gallery thumbnails
$tpl->clear_cache(null, "gallery|thumbnail");
// clear the cache for the file called "index.tpl"
$tpl->clear_cache("index.tpl");
// clear the cache for the file called "index.tpl" with the cache id of "homepage"
$tpl->clear_cache("index.tpl", "homepage");
clear_all_cachevoid clear_all_cache()
EXAMPLE ============================= // clear the whole cache $tpl->clear_all_cache();
is_cachedbool is_cached(string $file [, string $cache_id])
EXAMPLE
=============================
$tpl->caching = true;
if (!$tpl->is_cached("index.tpl", "homepage")) {
// do expensive database calls here
}
$tpl->display("index.tpl", "homepage");
register_modifiervoid register_modifier(string $modifier, callback $implementation)
$implementation can either be a string containing the function name, or an array of the form array(&$object, $method) with &$object being a reference to an object and $method being a string that contains the method name, or an array of the form array(&$class, $method) with &$class being a reference to a class and $method being a method of that class.
EXAMPLE
=============================
// map PHP's stripslashes function to a Template Lite modifier
// can be referenced like this: { $var|sslash } to strip slashes from variables
$tpl->register_modifier("sslash", "stripslashes");
// map to a custom function
$tpl->register_modifier("fix_string", "fix_string");
EXAMPLE MODIFIER
=============================
function fix_string($string) {
// strip slashes and then make the resulting string all lowercase
// and then capitalize all the first letters of every word
return ucword(strtolower(stripslashes($string)));
}
unregister_modifiervoid unregister_modifier(string $modifier)
EXAMPLE
=============================
// don't want template designers to strip tags from elements
$tpl->unregister_modifier("strip_tags");
register_functionvoid register_function(string $function, callback $implementation)
$implementation can either be a string containing the function name, or an array of the form array(&$object, $method) with &$object being a reference to an object and $method being a string that contains the method name, or an array of the form array(&$class, $method) with &$class being a reference to a class and $method being a method of that class.
EXAMPLE
=============================
// register the function "print_current_date" as the template function "date_now"
// can now be used like this: { date_now } or { date_now format="l, F j, Y" }
$tpl->register_function("date_now", "print_current_date");
EXAMPLE FUNCTION
=============================
function print_current_date($params, &$tpl) {
if(empty($params['format']))
$format = "m/d/Y"
return date($format, time());
}
unregister_functionvoid unregister_function(string $function)
EXAMPLE
=============================
$tpl->unregister_function("fetch");
register_blockvoid register_block(string $function, $string implementation)
$implementation can either be a string containing the function name, or an array of the form array(&$object, $method) with &$object being a reference to an object and $method being a string that contains the method name, or an array of the form array(&$class, $method) with &$class being a reference to a class and $method being a method of that class.
EXAMPLE
=============================
$tpl->register_block("translate", "do_translation");
EXAMPLE FUNCTION
=============================
function do_translation($params, $content, &$tpl) {
if (isset($content)) {
$lang = $params['lang'];
// do something with $content
return $translation;
}
}
EXAMPLE PHP
=============================
{ translate lang=br }
Hello, world!
{ /translate }
unregister_blockvoid unregister_block(string $function)
EXAMPLE
=============================
$tpl->unregister_block("translate");
register_compiler_functionvoid register_compiler_function(string $function, callback $implementation)
Use this dynamically register a compiler function. Pass in the compiler function name, followed by the PHP function name that implements it.
The php-function callback $implementation can either be a string containing the function name, or an array of the form array(&$object, $method) with &$object being a reference to an object and $method being a string that contains the method name, or an array of the form array(&$class, $method) with &$class being a reference to a class and $method being a method of that class.
Compiler functions are called only during compilation of the template. They are used for injecting PHP code or other content into the template.
EXAMPLE
=============================
$tpl->register_compiler_function("show_tplheader", "compiler_show_tplheader");
EXAMPLE FUNCTION
=============================
function compiler_show_tplheader($arguments, &$tpl)
{
return "\necho '" . $tpl->_file . " compiled at " . date('Y-m-d H:M'). "';";
}
EXAMPLE INSERTED INTO COMPILED TEMPLATE
=============================
<?php
echo 'index.tpl compiled at 2006-04-12 15:34';
?>
unregister_compiler_functionvoid unregister_compiler_function(string $function)
EXAMPLE
=============================
$tpl->unregister_compiler_function("show_tplheader");
template_existsbool template_exists(string $file)
displayvoid display(string $file [, string $cache_id]])
EXAMPLE
=============================
include("class.template.php");
$tpl = new template;
$tpl->display("index.tpl", "homepage");
fetchstring fetch(string $file, [, string $cache_id]])
EXAMPLE
=============================
include("class.template.php");
$tpl = new template;
$output = $tpl->fetch("index.tpl", "homepage");
echo $output;
config_loadbool config_load(string $file [, string $section_name [, string $var_name]])
true if the config file was successfullyl loaded and false otherwise.
EXAMPLE
=============================
// load all config values
$tpl->config_load("config.ini");
// load all config values from the [layout] section
$tpl->config_load("config.ini", "layout");
// load the "font_color" key
$tpl->config_load("config.ini", "layout", "font_color");
load_filterbool load_filter(string $filtertype , string $filter_name)
EXAMPLE
=============================
// load gzip output filter
$tpl->load_filter("output", "gzip");
trigger_errorbool trigger_error(string error_msg [, int level])
EXAMPLE
=============================
$tpl->trigger_error("Couldn't find your file.", E_USER_WARNING);