TYPO3 Flow Base DistributionPackagesApplications

Suggestion #28859

Implode ViewHelper

Added by Alex Kellner almost 4 years ago. Updated almost 4 years ago.

Status:New Start date:2011-08-09
Priority:Could have Due date:
Assigned To:- % Done:

0%

Category:-
Target version:-
Has patch:Yes Tags:

Description

I really often need a commaseparated list of subobjects in relation to my current object.
No problem with a foreach loop in fluid, but how to delete the last ","?

Could be fixed with a viewhelper - e.g.:

public function render($array, $field, $glue) {
    $string = '';
    foreach ($array as $object) {
        $string .= $object->{'get' . ucfirst($field)}(); // getTitle()
        $string .= $glue;
    }
    return substr($string, 0, (-1 * strlen($glue)));
}

History

#1 Updated by Marc Bastian Heinrichs almost 4 years ago

What about:


 <f:for each="{0:1, 1:2, 2:3, 3:4}" as="foo" iteration="fooIterator">
    {foo}
    <f:if condition="{fooIterator.isLast}">
    <f:then></f:then>
    <f:else>,</else>
    </f:if>
 </f:for>

#2 Updated by Alex Kellner almost 4 years ago

Didn't know .isLast - if this works, fine for me :)

Thx

Also available in: Atom PDF