Created
March 1, 2013 11:23
-
-
Save ikkez/5064037 to your computer and use it in GitHub Desktop.
a F3 Template extention, to render <select> tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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