HCKit-Template
view release on metacpan or search on metacpan
Template.pm view on Meta::CPAN
<h1>Header</h1>
]]>
</header>
results in '<h1>Header</h1>'.
=head1 BUILTIN FUNCTIONS
Followings are the list of builtin functions.
=over 4
=item B<foreach>
<{ foreach LIST [AS NAME] }>
BODY
<{ /foreach }>
For each item in LIST, it is bound to NAME and then BODY is rewritten.
If NAME is omitted, each item is bound to the name 'iter'.
For example:
<{ foreach num }>
<* iter *>
<{ /foreach }>
---DATA---
<num>1</num>
<num>2</num>
<num>3</num>
This results in:
1
2
3
Another example:
<{ foreach site as s }>
<a href="<* s.url *>"><* s.label *></a><br>
<{ /foreach }>
---DATA---
<site>
<href>http://www.yahoo.com</href>
<label>Yahoo!</label>
</site>
<site>
<href>http://www.google.com</href>
<label>Google</label>
</site>
This results in:
<a href="http://www.yahoo.com">Yahoo!</a>
<a href="http://www.google.com">Google</a>
Following preprocessors are effective for C<foreach>.
C<foreach:sep=SEP> proprocessor specifies separator between outputs of
iterations.
For example,
<{ foreach num foreach:sep=' | '}>
<* iter *>
<{ /foreach }>
---DATA---
<num>1</num>
<num>2</num>
<num>3</num>
This results in:
1 |
2 |
3
C<foreach:toggle=INIT> preprocessor introduces a new variable named
'toggle' that has initial value of INIT. After each iteration, the
variable 'toggle' is toggled between 0 and 1.
For example,
<{ foreach num as n foreach:toggle=0 }>
<div class="style-<* toggle *>"><* n *></div>
<{ /foreach }>
---DATA---
<num>1</num>
<num>2</num>
<num>3</num>
Results in:
<div class="style-0">1</div>
<div class="style-1">1</div>
<div class="style-0">1</div>
=item B<if>
<{ if EXPR }>
BODY
<{ /if }>
If EXPR evaluates to true, BODY is rewritten; otherwise, nothing is
output.
For example, following template
<{ if link }>
<* link.label *>
<{ /if }>
---DATA---
<link>
<label>Yahoo!</label>
<url>http://www.yahoo.com</url>
</link>
is rewritten to 'Yahoo!'.
( run in 2.048 seconds using v1.01-cache-2.11-cpan-71847e10f99 )