Project

General

Profile

Actions

Feature #45877

closed

Adding an UnlessViewHelper convenience

Added by Pascal Dürsteler over 11 years ago. Updated almost 10 years ago.

Status:
Closed
Priority:
Should have
Category:
Fluid
Target version:
-
Start date:
2013-02-27
Due date:
% Done:

0%

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

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.

Actions #1

Updated by Pascal Dürsteler over 11 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.

Actions #2

Updated by Stefan Neufeind over 11 years ago

Background for "unless" is that Ruby knows "unless" as a negation of "if". Hmm, or "f:if.not" maybe?

Actions #3

Updated by Gerrit Code Review about 11 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

Actions #4

Updated by Anja Leichsenring about 11 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.

Actions #5

Updated by Alexander Opitz about 10 years ago

  • Project changed from 2559 to TYPO3 Core
  • Category changed from Fluid: ViewHelpers to Fluid
  • Assignee set to Anja Leichsenring
Actions #6

Updated by Wouter Wolters almost 10 years ago

  • Status changed from Under Review to Closed

Fluid make the compiler work with this. https://review.typo3.org/#/c/31707/

Actions

Also available in: Atom PDF