[TYPO3-mvc] FLUID: extended loop features

Martin Kutschker masi-no at spam-typo3.org
Wed Jan 6 15:51:12 CET 2010


Hi!

I'm missing a few features of Smarty in the view helpers dedicated to rendering of loops. Smarty has
a few convenient "variables" which will tell you a bit about the state of the loop. Therefore I
propose a name attribute for all loop oriented view helpers.

Via this name you can access the state of the current iteration. So it is an iteration object. But
for convenience reasons I would allow to query also properties of the loop itself. If this it too
unclean for FLOW3 then two attributes (a loop and an iteration object) are the solution. As the loop
 object should IMHO be accessible after the execution of the loop, so this might be more welcome ;)

So which state properties do I want to query? Basically the loop counter. Everything else is purely
for convenience.

eg (with two attributes)
<f:for each="{foobar}" as="item" loop="data" iteration="row">
 <h3>{row.count}/{data.total}
 <f:if condition="{row.isFirst}"> ... </f:if>
</f:for>
<p>{data.total} items listed</p>

Of course you could expressions, but as the target group for templates are also non-technicians
gimmicks like "isFirst" will make using FLUID for them more natural.

Here's my list of states I want to check:

loop.total
iteration.index (0 based)
iteration.count (1 based)
iteration.isFirst
iteration.isLast
iteration.isOdd
iteration.isEven

As you can see "loop" has not much features, so it could be added to the iteration object as well.

Note: "total" and "isLast" should store the result of count() as it can be costly.

Masi

PS: The for view helper converts all objects to arrays. IMHO this is only needed if the loop is to
be iterated reversed, because only then an array operation is called (array_reverse)


More information about the TYPO3-project-typo3v4mvc mailing list