|
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 |
Stormtrooper Smarty Rookie
Joined: 26 Feb 2004 Posts: 6 Location: Silver Spring, MD
|
Posted: Thu Feb 26, 2004 12:57 pm Post subject: Ternary Operator |
|
|
Hi,
It would be nice to have some form of an Ternary operator in Smarty. ie: var = $istrue ? 'this' : 'that';
I'm not sure how it would be implemented within the syntax of Smarty currently. It would be partially possible to create a new function plugin to allow for something like this:
Code: | {ternary test=$mightbetrue true='yes' false='no!'} |
But from what I currently undestand of Smart (only started using it about a week ago) that doesn't allow for the 'test' to have an expression in it. Using {if}{else}{/if} is a little clunky for certain circumstances. Maybe someone else has an alternate solution. _________________ Jason Morriss
http://www.psychostats.com/ |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Feb 26, 2004 2:47 pm Post subject: |
|
|
It wouldn't be added to the core, this only obfuscates what can already be done with {if}{else}{/if}. However, write a custom function/modifier and post it to the wiki. Functionality suggestions:
function:
{ternary test=$mightbetrue true='yes' false='no' assign='foobar'}
modifier:
{$mightbetrue|ternary:'yes':'no'} |
|
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
|