Smarty {html_options} plugin with ‘disabled’ support
I needed the ability to disable certain HTML <select>
options in the Smarty {html_options}
plugin so I whipped up this version which allows just that.
This is a drop-in replacement for the existing {html_options}
plugin. Disabled options are defined by passing in an array of keys, or a single key, just like ‘selected’ options are defined.
The PHP end
<?php
$options = array(
'1' => 'foo',
'2' => 'bar',
'3' => 'baz',
)
$selected = 1;
$disabled = array(2, 3);
$smarty->assign('options', $options);
$smarty->assign('selected', $selected);
$smarty->assign('disabled', $disabled);
In the Smarty template
<select>
{html_options options=$options selected=$selected disabled=$disabled}
</select>
Upgrade today!
Download function.html_options.php here
And if you’re Monte, here’s the (almost trivial) diff. I’d love to see it in the next Smarty version :)