|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
sempere Smarty n00b
Joined: 17 Jul 2009 Posts: 3
|
Posted: Fri Jul 17, 2009 11:33 pm Post subject: Printar valor función php |
|
|
Buenas.
Antes de nada, avisar que soy novato...
El tema es que tengo una función php que me retorna un string, y desde el template quisiera printar el valor por un lado, y hacer una comparación en otro lado.
La comparación me funciona perfectamente ( { if mifuncion() == "" } ), pero no encuentro cómo printar el valor que mi función devuelve... He probado con {$mifuncion()}, con {mifuncion()}, pero me salta un error del Smarty...
¿Alguien me puede echar un cable?
¡Mil grácias! |
|
Back to top |
|
Davod Smarty Rookie
Joined: 29 Sep 2009 Posts: 21
|
Posted: Wed Sep 30, 2009 11:42 pm Post subject: |
|
|
Un poco tarde pero tarigo la respuesta:
¿Registraste la Función?
Para poder usar una Función de usuario, debes Registrarla con $smarty->register_function. Es algo que se encuenta en el manual; por favor léanlo completo antes de continuar traajando.
Quote: | <?php
$smarty->register_function('date_now', 'print_current_date');
function print_current_date($params, &$smarty)
{
if(empty($params['format'])) {
$format = "%b %e, %Y";
} else {
$format = $params['format'];
return strftime($format,time());
}
}
?> |
En el template:
Code: | {date_now}
{* or to format differently *}
{date_now format="%Y/%m/%d"} |
Primero, creamos una Función como de costumbre.
Segundo, Registramos la Función. El primer parámetro es el Nombre que usaremos en el Template, el segundo parámetro es el Nombre de la función dentro del Script.
Finalmente, en la Plantilla:
{mi_funcion num1='10' num2='50'}
Referencias:
http://www.smarty.net/manual/es/api.register.function.php |
|
Back to top |
|
alexzgz Smarty n00b
Joined: 03 Dec 2009 Posts: 3
|
Posted: Fri Dec 04, 2009 9:17 am Post subject: |
|
|
gracias me sirvio. |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|