Re: [SMARTY] Multiple Parameter Function
| From: | Yann Thomas-Gérard | Date: | Mon, 10 Jan 2005 09:26:59 +0000 |
| Subject: | Re: [SMARTY] Multiple Parameter Function | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-12132@lists.php.net to get a copy of this message | ||
Robert Kraig wrote:
How would i pass multiple parameters to a function in smarty, like {index.php,4|Forward} from this function function Forward($location,$timer) {The params of your function must be contained in one array. Here's an example : - Definition of the function : function lpf_print_error($params) {return "<META HTTP-EQUIV=\"refresh\" CONTENT=\"".$timer."; URL=".$location."\">";}
$field = $params['field'];
$err = $params['err'];
if (array_key_exists($field, $err)) {
$r = '';
foreach($err[$field] as $k => $v) {
if ( $v === FALSE ) {
$t = TRUE;
$r .= '<li>Rule <strong>' . $k . '</strong>
is not satisfied</li>';
}
}
if (isset($t) && $t === TRUE) {
return '<ul class="error">' . $r . '</ul>';
}
return null;
}
return null;
}
- Register the function in the php file :
$smarty->register_function('lpf_print_error','lpf_print_error');
- Call of the function in the template :
{lpf_print_error field="civility" err=$err}