Re: [SMARTY] Multiple Parameter Function

From: Date: Mon, 10 Jan 2005 13:08:52 +0000
Subject: Re: [SMARTY] Multiple Parameter Function
References: 1 2  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12134@lists.php.net to get a copy of this message
Instead of doing that, i just decided to do this {index.php-4|Forward} using this function function Forward($var) { list($filename,$timer) = explode("-",$var); return "<META HTTP-EQUIV=\"refresh\" CONTENT=\"".$timer.";
URL=".$location."\">"; }
and that seems to work pretty good Yann Thomas-Gérard wrote:
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) {
    return "<META HTTP-EQUIV=\"refresh\" CONTENT=\"".$timer."; URL=".$location."\">";
}
The params of your function must be contained in one array. Here's an example : - Definition of the function : function lpf_print_error($params) {
    $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}


« previous php.smarty.general (#12134) next »