<< Back to index
Template Syntax
Place holder
Data can be injected into template with the syntax ${some_value}, which is also known as a place holder.
The place holder are vary from each template, please read about the list of place holders available for every module.
There are two types of place holder, which are classified as array place holder and hash place holder.
The array place holder are written as @{some_array_values}, it usually contains hashes value that can be looped
with [for(@{some_arrays_values})] statement. A hash place holder are value key pairs that are usually written as ${some_hash_value}.
Lets look at a simple example to display a user information:
<font face='Arial' size='4' color='green'>
My name is
<a href='/somepage/user-user-view.go?username=${username}'>
${firstname} ${lastname}
</a>
</font>
Assume ${firstname} holds the value of 'Azuka', ${lastname} holds the value of 'Kazama' and ${username} holds the value of 'azukameta',
the above template will give you the following output.
My name is Azuka Kazama
For loop
For loop function is used to loop through an array of hash values into the
designated block of template until its contained records are completely looped.
The usage of each [for(...)] tag must ends with [/for] tag.
You can also use [if(...)] condition tag within the [for(...)] tag.
Syntax:
[for(@{array_values})]
${hash_value1} ${hash_value2} ${hash_value3}
[/for]
Lets look at a simple example, a template to display a list of users:
<table border='1'>
<tr>
<td><b>First name</b></td>
<td><b>Last name</b></td>
<td><b>Username</b></td>
</tr>
[for(@{user_list})]
<tr>
<td>${firstname}</td>
<td>${lastname}</td>
<td>${username}</td>
</tr>
[/for]
</table>
Assume @user_list contains 5 records in the array which holds the following data:
- Angel Sliming angie
- Victoria Choy vicy
- Jojo Lena jojodes
- Paul Philips paulphil
- Lina Williams linawill
The above example will gives you the following output.
| First name |
Last name |
Username |
| Angel |
Sliming |
angie |
| Victoria |
Choy |
vicy |
| Jojo |
Lena |
jojodes |
| Paul |
Philips |
paulphil |
| Lina |
Williams |
linawill |
Now, lets explore the more advance usage of [for(...)] tag that comes with a devision number.
In the syntax below, ${devision} can be any integer number that will be used to devide
rows of records with a table wrapper.
Syntax:
[for(@{array_values} : ${devision})]
${hash_value1} ${hash_value2} ${hash_value3}
[/for]
For instance if you want to show 3 records per row of a list you can write it as the followings
[for(@{array_values} : 3)]
${firstname} ${lastname}<br>
${username}<br>
[/for]
The above example will gives you the following output, 3 columns are devided.
Angel Sliming
angie
|
Victoria Choy
vicy
|
Jojo Lena
jojodes
|
Paul Philips
paulphil
|
Lina
Williams
linawill
|
|
If condition
The [if(...)] tag is the the control flow tag for the template.
It executes a certain block of template only if a particular test of expression is true.
The expression are the combination of operators and place holder.
Please remember that each [if(...)] tag must ends with [/if] tag. In within a [if(...)] tag you can
also specify [elsif(...)] and [else] tag. You can even place a nested [if(...)] tag in within another [if(...)] tag.
Syntax:
[if(${a} eq 'some value')]
...block of template...
[elsif(${a} eq ${b} && ${a} ne ${c})]
...block of template...
[elsif(${a} == ${d} || ${a} >= ${e})]
[if(${a} <= ${f})]
...block of template...
[/if]
[else]
...block of template...
[/if]
Operators
The followings are the operators that can be used in the [if] condition
| Operator |
Description |
| eq |
String is equal to a value.
Example [if(${a} eq ${b})] is true if the value of place holder ${a} is equal to place holder ${b}. |
| ne |
String is not equal to a value.
Example [if(${a} ne ${b})] is true if the value of place holder ${a} is not equal to place holder ${b}. |
| == |
Numberic equal to a value.
Example [if(${a} == ${b})] is true if the numeric value of place holder ${a} is equal to place holder ${b}. |
| != |
Numberic inequal to a value.
Example [if(${a} != ${b})] is true if the numeric value of place holder ${a} is not equal to place holder ${b}. |
| > |
Numberic greater than a value.
Example [if(${a} > ${b})] is true if the numeric value of place holder ${a} is greater than place holder ${b}. |
| < |
Numberic lesser than a value.
Example [if(${a} < ${b})] is true if the numeric value of place holder ${a} is lesser than place holder ${b}. |
| >= |
Numberic greater or equal to a value.
Example [if(${a} > ${b})] is true if the numeric value of place holder ${a} is greater or equal to place holder ${b}. |
| <= |
Numberic lesser or equal to a value.
Example [if(${a} < ${b})] is true if the numeric value of place holder ${a} is lesser or equal to place holder ${b}. |
|