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

Using a *function*, not a modifier in smarty template?

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


Joined: 10 Jun 2016
Posts: 3

PostPosted: Fri Jun 10, 2016 9:33 am    Post subject: Using a *function*, not a modifier in smarty template? Reply with quote

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


Joined: 10 Jun 2016
Posts: 3

PostPosted: Fri Jun 10, 2016 10:06 am    Post subject: Reply with quote

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
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Sat Jun 11, 2016 9:20 am    Post subject: Reply with quote

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


Joined: 10 Jun 2016
Posts: 3

PostPosted: Tue Jun 14, 2016 6:56 am    Post subject: Reply with quote

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
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 -> General 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