10. Processing data in template with function

It is possible to process data in template when it is displayed. Syntax of the template function is "function(parameter):keyOfData". Part of "(parameter)" can be omitted.

10.1. Built-in functions

ZOGAN provide functions below.

Table 1. ZOGAN Built-in functions

date date() function. The parameter is format string.
sprintf sprintf() function. The parameter is format string.
not provides `NOT` logical operator. No parameter.
bool casts data to boolean value. No parameter.

Now only date and printf have been implemented. The format string is the same of date() and printf() function.

  <p var:cont="{date(F j, Y, g:i a):date}"></p>
  <p var:cont="{sprintf(I love %s):printf}"></p>

10.2. User defined functions

For user defined functions, use addFunction() method.

<table border="1">
  <tr var:cont="{numbers}">
    <td var:cont="{number}"></td><td var:cont="{category:number}"></td>

function getCategory($num, $param, $option)
    if ($num < 100) {
        return 'Small';
    elseif ($num < 200) {
        return 'Medium';
    else  {
        return 'Large';

$tmpl = new zogan;
// snip
$tmpl->addFunction('category', 'getCategory');
$nums = array();
for ($i =0; $i < 10 ;$i++ ) {
    $nums[] = array('number' => mt_rand(0,300));
$nums = array('numbers' => $nums);