Suggestion #28859

Implode ViewHelper

Added by Alex Kellner about 10 years ago. Updated about 10 years ago.

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

0%

Estimated time:
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)));
}

#1

Updated by Marc Bastian Heinrichs about 10 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 about 10 years ago

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

Thx

Also available in: Atom PDF