Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Printar valor función php

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: Spanish
View previous topic :: View next topic  
Author Message
sempere
Smarty n00b


Joined: 17 Jul 2009
Posts: 3

PostPosted: Fri Jul 17, 2009 11:33 pm    Post subject: Printar valor función php Reply with quote

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
View user's profile Send private message
Davod
Smarty Rookie


Joined: 29 Sep 2009
Posts: 21

PostPosted: Wed Sep 30, 2009 11:42 pm    Post subject: Reply with quote

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
View user's profile Send private message
alexzgz
Smarty n00b


Joined: 03 Dec 2009
Posts: 3

PostPosted: Fri Dec 04, 2009 9:17 am    Post subject: Reply with quote

gracias me sirvio.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: Spanish All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP