![]() |
Flat-Frog - the faster compiling PHP template engine |
assign
void 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_config
void 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
void clear([string $key])
void clear([array $key])
EXAMPLE ============================= // clear a single variable $tpl->clear("Name"); // clear a multiple variables $tpl->clear(array("Name", "Address)); // clear all variables $tpl->clear();
clear_config
void 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_vars
mixed get_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_vars('foo'); // get all assigned template variables $tpl_vars = $tpl->get_vars();
get_vars_config
mixed 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
void clear_compiled([string $file])
EXAMPLE ============================= // clear all compiled files $tpl->clear_compiled(); // clear the compiled file for the file called "index.tpl" $tpl->clear_compiled("index.tpl");
clear_cached
void clear_cached([string $file [, string $cache_id]])
EXAMPLE ============================= // clear the whole cache $tpl->clear_cached(); // clear all files in the "gallery" group, such as "gallery|view" and "gallery|thumbnail" $tpl->clear_cached(null, "gallery"); // clear only the gallery thumbnails $tpl->clear_cached(null, "gallery|thumbnail"); // clear the cache for the file called "index.tpl" $tpl->clear_cached("index.tpl"); // clear the cache for the file called "index.tpl" with the cache id of "homepage" $tpl->clear_cached("index.tpl", "homepage");
is_cached
bool 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_modifier
void 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 Flat-Frog 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_modifier
void unregister_modifier(string $modifier)
EXAMPLE ============================= // don't want template designers to strip tags from elements $tpl->unregister_modifier("strip_tags");
register_function
void 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_function
void unregister_function(string $function)
EXAMPLE ============================= $tpl->unregister_function("fetch");
register_block
void 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_block
void unregister_block(string $function)
EXAMPLE ============================= $tpl->unregister_block("translate");
template_exists
bool template_exists(string $file)
display
void display(string $file [, string $cache_id]])
EXAMPLE ============================= include("class.template.php"); $tpl = new template; $tpl->display("index.tpl", "homepage");
fetch
string fetch(string $file, [, string $cache_id]])
EXAMPLE ============================= include("class.template.php"); $tpl = new template; $output = $tpl->fetch("index.tpl", "homepage"); echo $output;
config_load
bool 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");