Suggestion #5948

join

Added by Martin Kutschker over 11 years ago. Updated almost 11 years ago.

Status:
New
Priority:
Should have
Assignee:
-
Start date:
2010-01-10
Due date:
% Done:

0%

Estimated time:
Has patch:
Tags:

Description

Sometimes you want to concatenate elements as a comma separated list. Or maybe you want to put the elements in different lines by <br>.

The attached file implements this feature:

Shortest possible syntax:

<f:join each="{0: 'apple', 1: 'banana'}" by=" and " />

Typical syntax:

<f:join each="{0: 'apple', 1: 'banana'}" as="fruit" by=" and " >{fruit}</f:join><br>

Long syntax:

<f:join each="{0: 'apple', 1: 'banana'}" as="fruit">
<f:item>{fruit}</f:item>
<f:by> and </f:by>
</f:join>

The necessary "item" and "by" view helpers are similar to "then" and "else".


Files

JoinViewHelper.php (4.46 KB) JoinViewHelper.php Martin Kutschker, 2010-01-10 10:41
#1

Updated by Martin Kutschker over 11 years ago

Perhaps an optional argument "lastBy" eases things even more:

<f:join each="{0: 'apple', 1: 'banana', 2: 'mango'}" by=", " lastBy=" and " />

Which would yield: "apple, banana and mango"

#2

Updated by Bastian Waidelich about 11 years ago

  • Tracker changed from Feature to Suggestion
  • Project changed from TYPO3.Fluid to Fluid - ViewHelper - Incubator
#3

Updated by Bastian Waidelich about 11 years ago

  • Subject changed from an implode/join view helper for convenience to join

Also available in: Atom PDF