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

get array item from custom function

 
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 -> Smarty Development
View previous topic :: View next topic  
Author Message
matt86
Smarty n00b


Joined: 04 Dec 2012
Posts: 2

PostPosted: Tue Dec 04, 2012 9:23 am    Post subject: get array item from custom function Reply with quote

Hello,
I've a problem with register_function.

I created a function in this way:
Code:

function hello($params)
{
   $a = $params['a'];
   $b = $params['b'];
   return array('A' => $a, 'B' => $b);
}


so, I registered the function in this way:

Code:

$Template->register_function('hello', 'hello');


then in my template I wrote:

Code:

{$foo = {hello a=60 b=30}}
<b>{$foo.B}</b>


the problem is that the template print always "Array" and not the value "30" (in this case)

where I wrong?
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Dec 04, 2012 10:33 pm    Post subject: Reply with quote

Note that function plugins are expected to return printable values.

For other cases the standart procedure is that the plugin accepts an assign parameter with the variable which should recieve the result.

Code:
function hello($params, $smarty)
{
   $a = $params['a'];
   $b = $params['b'];
   $smarty->assign( $params['assign'], array('A' => $a, 'B' => $b));
}


Code:
{hello a = 10, b =30, assign = 'foo'}
{$foo.B}
Back to top
View user's profile Send private message
matt86
Smarty n00b


Joined: 04 Dec 2012
Posts: 2

PostPosted: Wed Dec 05, 2012 6:31 am    Post subject: Reply with quote

Great!
now it work!

thanks

U.Tews wrote:
Note that function plugins are expected to return printable values.

For other cases the standart procedure is that the plugin accepts an assign parameter with the variable which should recieve the result.

Code:
function hello($params, $smarty)
{
   $a = $params['a'];
   $b = $params['b'];
   $smarty->assign( $params['assign'], array('A' => $a, 'B' => $b));
}


Code:
{hello a = 10, b =30, assign = 'foo'}
{$foo.B}
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 -> Smarty Development 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