Documentation / Documentation for web designers / RainTPL Tags 

{$variable}

Variables are the dynamic contents of the template, valorized in the execution of the script with RainTPL assign() method.
Variable names are case sensitive.


Example:

My favourite color is <span style="color:{$color};">{$color}</span>


Output:

My favourite color is blue

 

 

Operation with variables

You can use arithmetic operators for simple operations: +, -, *, /, %, .

Example:

<!-- $num value is 2 -->
{$num + 10}
<!-- $a value is 1, $b value is 2 -->
{$a + $b}


Output:

12
3



Initialize a variable

Also if should be done in the PHP layer, is possible to initialize a variable value with the = operator:

Example:

{$zero=0}
{$var="Hello world!"}



Arrays and objects

Variables can be either one-dimensional (strings, numbers, boolean values) and multidimensional (arrays, objects).
To access array values use the dot operator "." and to access object values use the arrow operator "->".
To access array use the {loop} tag.


Example:
Array :

  • website =>
    • name => Rain
    • url => http://www.raincms.com


Template:

Website <b>{$website.name}</b> url {$website.url}


Output:

Website Rain url http://www.raincms.com



Global Variables

You can use {$GLOBALS} into template to access globals value.

Template:

{$GLOBALS.variable}



Show all assigned variables

You can use the special variable {$template_info} to see all the variables assigned to your template

Template:

{$template_info}

 

  ^ RainTPL Tags ^ {#constant#} »

Documentation for web designers




Documentation for PHP developers