Feature #45877
Adding an UnlessViewHelper convenience
Status: | Closed | Start date: | 2013-02-27 | |
---|---|---|---|---|
Priority: | Should have | Due date: | ||
Assigned To: | Anja Leichsenring | % Done: | 0% |
|
Category: | Fluid | Spent time: | - | |
Target version: | - | |||
PHP Version: | Sprint Focus: | |||
Complexity: | easy |
Description
AFAIK, you currently have to do something like this if you want to conditionally display something if it is not the case:
<f:if condition="{...}"> <f:then></f:then> <f:else> I just want this to be displayed and don't need the "if true case". </f:else> </f:if>
Peeking at ruby, I think some syntactic sugar could simplify this:
<f:unless condition="{...}"> <f:then>I like this</f:then> </f:unless>
This, of course, also accepts an else block. With this, however, you'll have the same amount of markup, but it may integrate better into your view logic.
<f:unless condition="{...}"> <f:then>not the case</f:then> <f:else>the case</f:else> </f:if>
If this does not encounter much resistance, I'd like to submit a patch.
Related issues
History
#1 Updated by Pascal Dürsteler over 2 years ago
Just saw that it also may work this way:
<f:if condition="{...}"> <f:else>...</f:else> </f:if>
I think an UnlessViewHelper would still be the better choice regarding readability, though.
#2 Updated by Stefan Neufeind almost 2 years ago
Background for "unless" is that Ruby knows "unless" as a negation of "if". Hmm, or "f:if.not" maybe?
#3 Updated by Gerrit Code Review almost 2 years ago
- Status changed from New to Under Review
Patch set 1 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/24633
#4 Updated by Anja Leichsenring almost 2 years ago
I am fine with unless, but not with the implementation as is. Better to reverse the if VH. No shorthand syntax for this is not the way.
consider this use case:
<f:for each="{entries} as="entry" iteration="foo"> <li class="{f:unless (condition:foo.isLast, then: 'list_entry', else:'list_entry_last)}"></li> </f:for>
If noone objects, I will push a new patchset reversing the if VH. Let me know what you think.
#5 Updated by Alexander Opitz 11 months ago
- Project changed from Fluid to Core
- Category changed from Fluid: ViewHelpers to Fluid
- Assigned To set to Anja Leichsenring
#6 Updated by Wouter Wolters 7 months ago
- Status changed from Under Review to Closed
Fluid make the compiler work with this. https://review.typo3.org/#/c/31707/