html_options

Attribute NameTypeRequiredDefaultDescription
valuesarrayYes, unless using options attributen/aan array of values for dropdown
outputarrayYes, unless using options attributen/aan array of output for dropdown
selectedstringNoemptythe selected array element
optionsassociative arrayYes, unless using values and outputn/aan associative array of values and output

html_options is a custom function that creates html option lists with provided data. It takes care of which item is selected by default as well. Required attributes are values and output, unless you use options instead.

NOTE: As of Smarty 1.4.5, html_options now outputs xhtml compatible code.

Example 8-6. html_options

{* assume that $cust_ids, and $cust_names are arrays of values,
	and $customer_id may or may not be set to a value *}

<select name=customer_id>
	{html_options values=$cust_ids selected=$customer_id output=$cust_names}
</select>


{* an alternative method is to pass the values & output as an associative array into
   options. $customer_options is an associative array in this example. *}

<select name=customer_id>
	{html_options options=$customer_options selected=$customer_id}
</select>


OUTPUT:

<select name=customer_id>
	<option value="1000">Joe Schmoe</option>
	<option value="1001" selected="selected">Jack Smith</option>
	<option value="1002">Jane Johnson</option>
	<option value="1003">Charlie Brown</option>
</select>