Issue Bug Rejected

#84157iterator.isLast does not work correctly - sorry! Working as expected! Please delete!

Gone With the Wind 03/07/18, 10:36 updated 03/07/18, 11:11

Description

From what I understand, the “isLast” param is a boolean compared again “total”:

// FluidTypo3: "For" viewhelper, lines 124ff:
if (isset($arguments['iteration'])) {
    $iterationData['isFirst'] = $iterationData['cycle'] === 1;
    $iterationData['isLast'] = $iterationData['cycle'] === $iterationData['total'];      <-- here!
    $iterationData['isEven'] = $iterationData['cycle'] % 2 === 0;
    $iterationData['isOdd'] = !$iterationData['isEven'];
    $templateVariableContainer->add($arguments['iteration'], $iterationData);
    $iterationData['index']++;
    $iterationData['cycle']++;
}

But this:

<f:spaceless>
<f:for each="{person.roles}" as="role" iteration="i">
    <f:if condition="{i.isFirst}">(</f:if>{i.index} - {role.name} (total: {i.total}, isFirst: {i.isFirst}, isLast: {i.isLast})<f:if condition="{i.cycle} < {i.total}">,&nbsp;</f:if>
    <f:if condition="{i.isLast}">)</f:if>
</f:for>
</f:spaceless>

results into this:

(0 - Cook (total: 2, isFirst: 1, isLast: ),  1 - waiter(total: 2, isFirst: , isLast: 1) )

On the first iteration, isLast is empty, which seems to be interpreted as “true”, therefore the closing parenthesis is set – which is wrong.

On a side note:
Shouldn’t <f:spaceless> remove the whitespace between the <f:if> within the loop? It does not and instead prints the whitespace…</f:if></f:spaceless>

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.