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

Ternary Operator

 
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 -> Feature Requests
View previous topic :: View next topic  
Author Message
Stormtrooper
Smarty Rookie


Joined: 26 Feb 2004
Posts: 6
Location: Silver Spring, MD

PostPosted: Thu Feb 26, 2004 12:57 pm    Post subject: Ternary Operator Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Feb 26, 2004 2:47 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
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 -> Feature Requests 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