User's Manual

Conditional Text Blocks
To include a block of text only if a particular condition is true, use the following syntax:
{if $username != ""}
<tr>
<td class="nwaBody">Username:</td>
<td class="nwaBody">{$username}</td>
</tr>
{else}
<!-- No user name, no table row -->
{/if}
The condition tested in the {if} {/if} block should be a valid PHP expression. The {else} tag does not require
a closing tag.
Script Blocks
The brace characters { and } are specially handled by the Smarty template engine. Using text that contains
these characters, such as CSS and JavaScript blocks, requires a Smarty block {literal} … {/literal}:
<script type="text/javascript" language="JavaScript">
{literal}
<!--
function my_function() {
// some Javascript code here
}
// -->
{/literal}
</script>
Failing to include the {literal} tag will result in a Smarty syntax error when using your template. Single
instances of a { or } character can be replaced with the Smarty syntax {ldelim} and {rdelim} respectively.
Repeated Text Blocks
To repeat a block of text for each item in a collection, use the {section} … {/section} tag:
{section loop=$collection name=i}
<tr>
<td class="nwaBody">
{$collection[i].name}
</td>
</tr>
{sectionelse}
<!-- included if $collection is empty -->
{/section}
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.
Dell Networking W-ClearPass Guest 6.4 | User Guide Reference | 481