Smarty Forum Index Smarty
The discussions here are for Smarty, a template engine for the PHP programming language.

Short Form of IF - {$var ? 'foo' : 'bar'}

 
Post new topic   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Feature Requests
View previous topic :: View next topic  
Author Message
terryjohnson
Smarty Rookie


Joined: 03 Jan 2004
Posts: 9
Location: Chatham, ON, Canada

PostPosted: Mon Mar 15, 2004 9:16 pm    Post subject: Short Form of IF - {$var ? 'foo' : 'bar'} Reply with quote

If it is not already possible to do this (as an undocumented feature), please could it be added?

It would be very useful for translating boolean values into human-readable texts. For example:

Customer is {$bloke ? 'Male' : 'Female'}
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


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

PostPosted: Mon Mar 15, 2004 9:20 pm    Post subject: Reply with quote

You can do this with if/else pretty easily:

{if $bloke}Male{else}Female{/if}

If you want, you can make a modifier:

{$bloke|bool:"Male":"Female"}
Back to top
View user's profile Send private message Visit poster's website
kloshar4o
Smarty n00b


Joined: 23 Feb 2019
Posts: 1

PostPosted: Sat Feb 23, 2019 7:30 pm    Post subject: Reply with quote

I dont know why is it so hard to find this on the internet, but here it is :

{($bloke) ? 'Male' : 'Female'}
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1506

PostPosted: Sun Feb 24, 2019 12:08 pm    Post subject: Reply with quote

Perhaps, because it was asked 15 years ago?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   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