Templight

Conditions

In any block structure of TempLight (loop, recursion, regexvar), conditions could be used to generate custom text.

For that purpose a standard if, elseif, else structure is provided. The tests are performed on a unique object called node that represent the current node of information that is rendered.

This node object contains several functions to retrieve usefull values. The Node class is defined at the end of TempLight file and can easily be extended acording your needs.

A list of available functions

Of course you are free to add new functions to the Node object. You are even ecouraged to do so.

Example

An example that generate a sitemap with condition :

$nestedNavigation = array(
    array("text"=>'Enterprise','link'=>'http://www.dosimple.ch/Enterprise/',
        array("text"=>'Sales','link'=>'http://www.dosimple.ch/Sales/'),
        array("text"=>'Orders','link'=>'http://www.dosimple.com/Orders/')
    ),
    array("text"=>'Agenda','link'=>'http://www.dell.com/',
        array("text"=>'Agenda details','link'=>'http://www.dosimple.ch/'),
        array("text"=>'Agenda users','link'=>'http://www.dosimple.ch/',
            array("text"=>'Alice','link'=>'http://www.dosimple.ch/','current'=>true),
            array("text"=>'Bob','link'=>'http://www.dosimple.ch/'),
            array("text"=>'John','link'=>'http://www.dosimple.ch/')
        )
    ),
    array("text"=>'Contact','link'=>'http://www.dosimple.ch/',
        array("text"=>'Alice','link'=>'http://www.dosimple.ch/'),
        array("text"=>'Bob','link'=>'http://www.dosimple.ch/'),
        array("text"=>'John','link'=>'http://www.dosimple.ch/')
        ),
    );

$tpl->recursiveReplace('basic',$nestedNavigation);
<recursion name="siteMap">
<if test="node.level()==1">
<loop><h2><a href="<var name="link"/>">
<var name="text"/></a></h2><recursion/></loop>
<else/>
<ul>
    <loop>
        <li>
            <a href="<var name="link"/>">
                <var name="text"/> 
                <if test="node.field(current)==true">
                «-- you are here</if>
            </a>
        <recursion/>
        </li>
    </loop>
</ul>
</if>
</recursion>