#84157iterator.isLast does not work correctly - sorry! Working as expected! Please delete!
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}">, </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.