Skip to main content
Version: Fegg 5.x (next)

Options

Make option tags

Description​

{{ options source=$list selected=$currentValue }}

Prints one <option> for each element of source: the array key is the value attribute and the array value is the label. Both are HTML-escaped.

The option whose key equals selected (compared as strings) gets the selected attribute. selected is optional. Nothing is printed when source is empty.

Write the arguments without spaces inside them (source=$page.categories, not an expression). For a multiple select, use checked/selected in a foreach instead.

Example​

Controller
$this->page['categories'] = array(
'1' => 'News',
'2' => 'Events & Seminars',
);
Template
<select name="category">
<option value="">All</option>
{{ options source=$page.categories selected=$in.category }}
</select>
Output (request ?category=2)
<select name="category">
<option value="">All</option>
<option value='1'>News</option><option value='2' selected>Events &amp; Seminars</option>
</select>