Ternary operators #660
Replies: 5 comments 2 replies
-
bump - I want this too for templates. Example with "elvis" operator
could be simplified to
Thx |
Beta Was this translation helpful? Give feedback.
-
Can't this already be done with "default"?`{$myvar|default:"foobar"}`On Apr 30, 2023 7:05 AM, tpneumat ***@***.***> wrote:
bump - I want this too for templates. Example with "elvis" operator
{if $myvar}{$myvar}{else}N/A{/if}
could be simplified to
{$myvar?:'N/A'}
Thx
—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you are subscribed to this thread.Message ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
Funny thing is that Smarty supports the ternary since 2009/2010. But it was never documented. Also, it requires the testing expression to be in parentheses. So this should work: {($foo) ? $var1 : $var2} But this will not: {$foo ? $var1 : $var2} There is no support for the shorthand |
Beta Was this translation helpful? Give feedback.
-
Ternary support is implemented in v5 |
Beta Was this translation helpful? Give feedback.
-
Thank you! |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Please implement support for ternary operators such as $foo ?: null, $foo?->prop, $foo ? $var1 : $var2☺️
These ternary operators are very helpful in simplifying code. Thanks in advance
Beta Was this translation helpful? Give feedback.
All reactions