|
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 |
matt86 Smarty n00b
Joined: 04 Dec 2012 Posts: 2
|
Posted: Tue Dec 04, 2012 9:23 am Post subject: get array item from custom function |
|
|
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 |
|
U.Tews Administrator
Joined: 22 Nov 2006 Posts: 5068 Location: Hamburg / Germany
|
Posted: Tue Dec 04, 2012 10:33 pm Post subject: |
|
|
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 |
|
matt86 Smarty n00b
Joined: 04 Dec 2012 Posts: 2
|
Posted: Wed Dec 05, 2012 6:31 am Post subject: |
|
|
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 |
|
|
|
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
|