|
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 |
konrados Smarty n00b
Joined: 10 Jun 2016 Posts: 3
|
Posted: Fri Jun 10, 2016 9:33 am Post subject: Using a *function*, not a modifier in smarty template? |
|
|
Hello.
I'm using Smarty v. 2.6.28 (old, legacy code).
I have an array in Smarty template. I do "foreach".
Now I need to do {if someFunction ($row.var1, $row.var2) } .... I hope you know what I mean. I need to pass two arguments to a function available in Smarty template.
The someFunction is the PHP function, right now it is registered with register_function
I thought I can do something like this:
{if checkRights role=$row.userRole activity=$row.userActivity} ...
But it ends up with:
PHP Parse error: syntax error, unexpected quoted-string (T_CONSTANT_ENCAPSED_STRING) in xyz/smarty/Smarty.class.php(1935) : eval()'d code on line 26
So, how can I do this?
Update:
Calling the function without "if" works fine. But I need it in "if". |
|
Back to top |
|
konrados Smarty n00b
Joined: 10 Jun 2016 Posts: 3
|
Posted: Fri Jun 10, 2016 10:06 am Post subject: |
|
|
OK, never mind - I handled it.
I do $smarty->assign('result',$someResult) in registered function and then I read that value in Smarty template. |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Sat Jun 11, 2016 9:20 am Post subject: |
|
|
I would adwise to rethink.
Sudden appearance of variables is a headache you don't want to deal with in any project.
What if the next maintainer of your code pass the same named variable to the template, and you just screw it with your stealth assign? |
|
Back to top |
|
konrados Smarty n00b
Joined: 10 Jun 2016 Posts: 3
|
Posted: Tue Jun 14, 2016 6:56 am Post subject: |
|
|
Thanks AnrDaemon, I haven't noticed your answer, and got no notification.
How do you suggest to do that?
Smarty (at least in my version) doesn't allow { if some_function params1=something } |
|
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
|