HTML-CTPP2
view release on metacpan or search on metacpan
lib/HTML/CTPP2.pm view on Meta::CPAN
(local and global) and user defined functions inside of the operator's body.
Example 2.1
<TMPL_if LOGICAL_EXPR>
Some instructions if result has true value.
<TMPL_elsif OTHER_EXPRESSION>
Some instructions if result has false value.
<TMPL_else>
Else-branch/
</TMPL_if>
<TMPL_unless LOGICAL_EXPR1>
Some instructions if result has false value.
<TMPL_elsif LOGICAL_EXPR2>
Some instructions if evaluation result of
LOGICAL_EXPR2 has true value.
<TMPL_else>
Some instructions if result has true value.
</TMPL_unless>
The branches of <TMPL_elsif> and <TMPL_else> are not firmly binds,
it means that the following notification is allowed:
<TMPL_if LOGICAL_EXPR> Some instructions </TMPL_if>.
Thus the operator <TMPL_unless differs from the operator <TMPL_if in the
executing some instructions if the evaluated value is false.
=head2 TMPL_loop
The loop - The multiple repeating of some pre-defined actions.
The first type of loops in CTPP - 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>
If you evidently put the mark to use context variables in the loop body,
CTPP inserts seven special variables, called context vars. The names of these
variables start with the double underline, this fact points to their system
meaning. Set of values for "context vars":
* __FIRST__ - sets to "1" during the first loop iteration,
in other cases not defined.
* __LAST__ - sets to the last iteration number,
otherwise is not defined.
* __INNER__ - accommodates the number from the second to the pre-last
iteration, otherwise undefined
* __OUTER__ - accommodates the number of first and last iteration, otherwise undefined
* __ODD__ - the number of an odd iteration. For the even one - undefined.
* __COUNTER__ - the number of current iteration.
* __RCOUNTER__ - whole number of the loop iterations minus the number of current iteration.
* __EVEN__ - opposite to the __ODD__ variable.
* __SIZE__ - the whole number of the loop iterations.
* __CONTENT__ - contains value of current iteration
=head2 TMPL_foreach
The second type of loops in CTPP - forward iteration through the data array
The operator corresponding with this action looks like the following:
<TMPL_foreach LOOP_NAME as ITERATOR>
<TMPL_var OBJ_DUMP(ITERATOR)>
The LOOP instructions.
</TMPL_foreach>
=head2 TMPL_include
In some cases it happens to allocate conveniently identical parts in several
templates (for example, heading or the menu on page) and to place them in one file.
This is done by operator <TMPL_include filename.tmpl>.
Example 3.1:
File `main.tmpl`:
<TMPL_loop foo>
<TMPL_include "filename.tmpl" map(bar : baz, orig_param : include_param)>
</TMPL_loop>
File filename.tmpl:
<TMPL_var baz>
You can rename variable in included templates. In example 3.1 variable 'baz'
in file 'filename.tmpl' was renamed to 'bar' and 'orig_param' to 'include_param'.
This is useful when you include one template many times in main template.
Attention! You CAN NOT place a part of a loop or condition in separate templates.
In other words, this construction will not work:
Example 3.2
File `main.tmpl`:
<TMPL_if foo>
<TMPL_include 'abc.tmpl'>
File `abc.tmpl`:
</TMPL_if>
=head2 TMPL_comment
All characters between <TMPL_comment> and </TMPL_comment> are ignored. This is
useful to comment some parts of template.
=head2 TMPL_block, TMPL_call
You can declare a block of code and call it by name:
Example 4.1:
<TMPL_block "foo"> <!-- Declare block with name "foo" -->
... some foo''s HTML and CTPP operators here ...
</TMPL_block>
<TMPL_block "bar"> <!-- Declare block with name "bar" -->
... some other HTML and/or CTPP operators here ...
</TMPL_block>
( run in 2.774 seconds using v1.01-cache-2.11-cpan-71847e10f99 )