Home > Archive > PHP Smarty Templates > January 2005 > Re: [SMARTY] Multiple Parameter Function
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Re: [SMARTY] Multiple Parameter Function
|
|
| Yann Thomas-Gérard 2005-01-10, 8:58 am |
| 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}
| |
| Robert Kraig 2005-01-10, 4:01 pm |
| 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.";
}
and that seems to work pretty good
Yann Thomas-Gérard wrote:[color=darkred]
> Robert Kraig wrote:
>
>
>
> 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}
|
|
|
|
|