Loops
The loop - The multiple repeating of some pre-defined actions.
The only type of loops has been defined in CT++ - the forward running over through the data array. The operator corresponding with this action looks like the following:
<TMPL_loop MODIFIERS LOOP_NAME>
The LOOP instructions.
</TMPL_loop>
There are four modifiers for this operato:
- __GLOBAL_VARS__ makes visible the global variables inside of the LOOP’s body.
- __NO_GLOBAL_VARS__ cancels the __GLOBAL_VARS__ modifier.
- __CONTEXT_VARS__ creates context variables inside the loop.
- __NO_CONTEXT_VARS__ cancels the __CONTEXT_VARS__ modifier.
Important! Changing these options affects the current loop and the all enclosed loops.
It is done to take off the collisions between put-in-loops, which occur while concurrently changed the __GLOBAL_VARS__ and __CONTEXT_VARS__ modifiers.
Example 3.1:
Template:
<table width="100%">
<TMPL_loop __CONTEXT_VARS__ EMPLOYEE_INFO>
<tr>
<td>#: <TMPL_var __COUNTER__></td>
<td>Name: <TMPL_VAR NAME></td>
<td>Job: <TMPL_VAR JOB></td>
</tr></TMPL_LOOP>
</table>
Parameters:
EMPLOYEE_INFO
[
{ NAME => "Ivanov Ivan", JOB => "The architect" },
{ NAME => "Petrov Petr", JOB => "The builder" }
]
Output:
<table width="100%">
<tr>
<td>1</td>
<td>Name: Ivanov Ivan</td>
<td>Job: The architect</td>
</tr>
<tr>
<td>2</td>
<td>Name: Petrov Petr</td>
<td>Job: The builder</td>
</tr>
</table>
Copyright © 2003 - 2005 CTPP Dev. Team | http://reki.ru/products/ctpp