Project

General

Profile

Actions

Feature #77275

closed

Opposite of IfViewHelper

Added by Daniel Corn over 7 years ago. Updated over 7 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Fluid
Target version:
-
Start date:
2016-07-28
Due date:
% Done:

0%

Estimated time:
PHP Version:
Tags:
Complexity:
easy
Sprint Focus:

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

Actions #1

Updated by Markus Klein over 7 years ago

  • Description updated (diff)
Actions #2

Updated by Markus Klein over 7 years ago

  • Status changed from New to Needs Feedback

Hi!

  1. you can leave out the empty <f:then>
  2. you can simply use a negated condition {foo} == 0
Actions #3

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?

Actions #4

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.

Actions #5

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.

Actions #6

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)

Actions #7

Updated by Daniel Corn over 7 years ago

Yes, feel free to close this.

Thank you for your feedback!

Actions #8

Updated by Riccardo De Contardi over 7 years ago

  • Status changed from Needs Feedback to Closed

Thanks for the quick response

Actions

Also available in: Atom PDF