How to access key and value of an array in smarty template?
Use key
in your foreach
:
{foreach from=$enquiries_labels item=label key=key}
<option value="{$key}" {if $data.key == $key} selected="selected" {/if}>{$label}
</option>
{/foreach}
It's all there in the documentation.
Smarty 3 foreach construction is like this
{foreach $products as $p}
{$p@key}: {$p}
{/foreach}
Use the key
attribute.
{foreach from=$enquiries_labels item="label" key="key"}
<option value="{$key}"{if $data.key == $key} selected="selected"{/if}>{$label}</option>
{/foreach}