Re: [SMARTY] if-else-routine bundled

[email protected] (Peggy Schatz) Fri, 17 Nov 2006 13:22:39 +0100
Newsgroups php.smarty.general
Message-ID <[email protected]>
Hello again,

I solved the problem by writing a wee plugin which (dependent on the 
data type) calls either the smarty_function for select-box-creation or 
writes code for input field and returns it.


************in the template****************

<td>{checkfield data=$templateVar value=$templateVar_value 
selected=$selected}</td>



***************in function.checkfield.php***************

function smarty_function_checkfield($params, &$smarty)
{
if (is_array($params['value'])) {
$res = 
smarty_function_html_options(array('name'=>$params['data']['name'], 
'options'=>$params['value'], 'selected'=>$params['selected'], 
'class'=>"bg" . $params['data']['farbe'], 'style'=>"width:" . 
$params['data']['breite'] . "px", 
'onchange'=>$params['data']['js']),$smarty);
}
else {
$res = "<input type=\"text\" name=\"" . $params['data']['name'] . "\" 
value=\"" . $params['value'] . "\" class=\"bg" . 
$params['data']['farbe'] . "\" size=\"" . $params['data']['breite'] . 
"\"" .  $params['data']['readstatus'] . "/>";
}
return $res;
}
**********************

Ciao,
Peggy