Feature #77275
closedOpposite of IfViewHelper
0%
Description
I think it would be good to have an inverse version of the IfViewHelper.
For me the following workaround is not very pretty:
<f:if condition="{condition}"> <f:then> </f:then> <f:else>This is the important part</f:else> </f:if>
My suggestion is to introduce the UnlessViewHelper, like in [Handlebars](http://handlebarsjs.com/builtin_helpers.html#unless)
<f:unless condition="{hopeFullyFalse}"> Alright, the variable is false </f:unless> <f:unless condition="{hopeFullyFalse}"> <f:then>Alright, the variable is false</f:then> <f:else>Sorry the variable is true</f:else> </f:unless>
PS: Sorry if this is a duplicate
Updated by Markus Klein over 7 years ago
- Status changed from New to Needs Feedback
Hi!
- you can leave out the empty
<f:then>
- you can simply use a negated condition
{foo} == 0
Updated by Daniel Corn over 7 years ago
Thank you for updating the description!
And thank you for your feedback! I wasn't aware that it's possible to leave the empty <f:then>
. Would solution 2 would also work for e.g. an empty array?
Updated by Markus Klein over 7 years ago
<f:if condition="{myArray}"> <f:else>Array is empty</f:else> </f:if>
<f:if condition="{myArray -> f:count()} == 0">Array is empty</f:if>
Small hint: Please use Slack to ask for help before you open tickets. thanks.
Updated by Daniel Corn over 7 years ago
On Slack I was suggested to open a ticket for feature requests.
IMHO the solutions are not optimal from a semantic perspective, but others may disagree.
Updated by Markus Klein over 7 years ago
Well, personally I dislike the "unless" stuff.
This is a feature only available in Ruby and other languages, but is not part of any of the major programming languages like C, C#, Java, etc.
IMO a developer should be able to simply negate a condition.
Fine with closing this?
(new basic viewhelpers like a f:unless should go into the standalone project anyway and not only into TYPO3 core)
Updated by Daniel Corn over 7 years ago
Yes, feel free to close this.
Thank you for your feedback!
Updated by Riccardo De Contardi over 7 years ago
- Status changed from Needs Feedback to Closed
Thanks for the quick response