Deployment Guide

Amigopod 3.7 | Deployment Guide Reference | 367
<!-- included if $collection is empty -->
{/section}
Note that the content after a {sectionelse} tag is included only if the {section} block would otherwise be
empty.
Foreach Text Blocks
An easier to use alternative to the {section} … {/section} tag is to use the {foreach} … {/foreach} block:
{foreach key=key_var item=item_var from=$collection}
{$key_var} = {$item_var}
{foreachelse}
<!—included if $collection is empty -->
{/foreach}
The advantage of this syntax is that each item in the collection is immediately available as the named item
variable, in this example {$item_var}. This construct is also useful when iterating through associative
arrays indexed by key, as the key is immediately available with each item.
A
name= attribute may be supplied with the opening {foreach} tag. When a name is supplied, the following
additional Smarty variables are available for use inside the {foreach} … {/foreach} block:
{$smarty.foreach.name.first} – true if the item being processed is the first item in the collection
{$smarty.foreach.name.last} – true if the item being processed is the last item in the collection
{$smarty.foreach.name.index} – counter for the current item, starting at 0 for the first item
{$smarty.foreach.name.iteration} – counter for the current item, starting at 1 for the first item
{$smarty.foreach.name.total} – value indicating the total number of items in the collection
Note that the content after a {foreachelse} tag is included only if the {foreach} block would otherwise be
empty.
Modifiers
Smarty provides modifiers that can be used to gain greater control over the formatting of data. Modifiers
can be included by following a variable with a vertical bar | and the name of the modifier. Any arguments to
the modifier can be specified using a colon : followed by the arguments.
The following example prints a date using the YYYY-MM-DD syntax:
{$expire_time|nwadateformat:"%Y-%m-%d"}
See “Date/Time Format Syntax” in this chapter for detailed information on the date/time format
modifiers. See Table 31.
Table 31 Smarty Modifiers
Modifier Description
htmlspecialchars Escapes characters used in HTML syntax with the equivalent HTML entities (&amp; for &,
&lt; for < and &gt; for >)
nl2br Replaces newline characters in the value with HTML line breaks (<br>)
number_format Formats a numerical value for display; an optional modifier argument may be used to
specify the number of decimal places to display (default is 0)
nwadateformat Date/time formatting; see “nwadateformat Modifier” in this chapter for details about this
modifier function
nwatimeformat Date/time formatting; see “Date/Time Format String Reference” in this chapter for
details about this modifier function