|
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 |
Lemon Juice Smarty Pro
Joined: 24 May 2006 Posts: 109
|
Posted: Tue Feb 07, 2017 10:33 am Post subject: How to create a plain function for use in {if}? |
|
|
I need to create a function for use in {if} structures in my templates and I can't find anything out of the available plug-in features that would make this easy. Twig appears to have this feature and it's used by Symfony:
Code: | {% if is_granted('ROLE_ADMIN') %} |
in Smarty I would like this:
Code: | {if is_granted('ROLE_ADMIN')} |
I would like to register this function in PHP (like with registerPlugin()) and use it in the templates. I know I could simply declare a global is_granted() function but that looks messy - I want the function only for use in the templates.
I can register the function with registerPlugin() and then use it like this:
Code: | {if {is_granted role='ROLE_ADMIN'}} |
but this syntax is a bit convoluted. Can I register a function so that I can use the simpler syntax like in my earlier example? |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Tue Feb 07, 2017 12:14 pm Post subject: |
|
|
You need a regular PHP function for that. No registering. |
|
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
|