|
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 |
gucki Smarty n00b
Joined: 09 Mar 2005 Posts: 4
|
Posted: Wed Mar 09, 2005 9:17 pm Post subject: in operator missing? |
|
|
hi!
as far as i know, there's no "in" operator like "if $val in ('dog','cat','bla')".
if not, why not and could it be added? should be relatively simple i think, just map it to in_array or so.
gucki |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Mar 09, 2005 9:24 pm Post subject: |
|
|
Good news: like all PHP functions, in_array can be used as a modifier so long as you aren't using secure mode. The only problem: you need to have your array predefined or you need a method to create an array from within the template if that is how you intend to do it.
{$needle|in_array:$haystack} |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Wed Mar 09, 2005 9:39 pm Post subject: |
|
|
or {if in_array($needle, $haystack)} ... {/if} |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Wed Mar 09, 2005 11:10 pm Post subject: |
|
|
**smacks head**
yes, that's a way better example since it shows its more likely usage |
|
Back to top |
|
gucki Smarty n00b
Joined: 09 Mar 2005 Posts: 4
|
Posted: Thu Mar 10, 2005 8:22 am Post subject: |
|
|
hey,
thanks so far. these methods i knew already, but i think it should be made simpler by adding an "in" operator, don't you think? wouldn't it be cool to have such a wonderful operator in smarty which also php misses? *G*
gucki |
|
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
|