Documentation / Documentation for web designers / RainTPL Tags 

{loop="array"}{/loop}

This tag reads arrays. Between the {loop} tag the following tags have special value:

  • {$key}, return the selected key.
  • {$value}, return the selected value. To access associative array you can use for example {$value.name}.
  • {$counter}, return the loop counter, which starts from 0. {$counter+1} start from 1, {$counter%2} will iterate values 1,0.

 

Example

// user_list = array( array('name'=>'Mars'), array('name'=>'Jupiter') ... )
{loop="user_list"}
{$key} - {$value.name}</br>
{/loop}


Output

0 - Mars
1 - Jupiter
2 - Earth



{loop="array"}{else}{/loop}

You can use {else} tag to output a message when the array is empty.

Example

 

// user_list = array()
{loop="user_list"}
{$key} - {$value.name}</br>
{else}
User List is empty
{/loop}


Output

User List is empty


« {if="condition"}{/if} ^ RainTPL Tags ^ {include="template"} »

Documentation for web designers




Documentation for PHP developers