Skip to content

Instantly share code, notes, and snippets.

@ikkez
Created March 1, 2013 11:23
Show Gist options
  • Save ikkez/5064037 to your computer and use it in GitHub Desktop.
Save ikkez/5064037 to your computer and use it in GitHub Desktop.
a F3 Template extention, to render <select> tags
/**
* sweetens <select>-TAG rendering with `group` attribute
* @param $args
* @return string
*/
static function renderSelect($args)
{
$attr = $args['@attrib'];
$tmp = \Template::instance();
foreach ($attr as &$att)
$att = $tmp->token($att);
$tags = '';
$html = (isset($args[0]))?$args[0]:'';
if (array_key_exists('group', $attr)) {
$html = '<?php foreach('.$attr['group'].' as $key => $val) {'.
' echo \'<option value="\'.$key.\'"\'.'.
'( ( isset($_REQUEST[\''.$attr['name'].'\']) && $_REQUEST[\''.$attr['name'].'\'] == $key)?'.
'\' selected="selected"\':\'\').\'>\'.$val.\'</option>\';'.'} ?>';
unset($attr['group']);
}
foreach ($attr as $key => $val)
$tags .= ' '.$key.'="'.$val.'"';
return '<select'.$tags.'>'.$html.'</select>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment