[TYPO3-mvc] Fluid - is there a way to check if an object is the first or last object?

Franz Koch typo3.RemoveForMessage at elements-net.de
Mon Jul 26 23:34:50 CEST 2010


Hey Bastian,

>> Tomorrow I'll try to add this extended for ViewHelper to the Incubator
>> distribution, then you'll be able to use it already.
>
> We've just extended the for ViewHelper with the iteration data (Thanks
> to a lot of patches from the community).
> So with the latest version of tx_fluid you can write:
>
> <f:for each="{items}" as="item" iteration="itemIteration">
> <li class="item{f:if(condition: itemIteration.isFirst, then: '
> first-child')}">{item}</li>
> </f:for>
>
> other iteration infos are:
> itemIteration.index (0 based index of the iteration)
> itemIteration.cycle (the same as index, but starting from 1)
> itemIteration.total (total number of items)
> itemIteration.isFirst (TRUE for the first item in the iteration)
> itemIteration.isLast (TRUE for the last item in the iteration)
> itemIteration.isOdd (TRUE for odd cycles 1,3,5,...)
> itemIteration.isEven (TRUE for even cycles 2,4,6,...)

thanks a lot. Do you think it would be an option to automatically add 
the itteration array to the view, even if no specific name was 
specified? I do this in my for-viewHelper and it's quite handsome 
(although not vital). I simply add "Iteration" to the "as" part of the 
viewHelper. So this would work:

<f:for each="{items}" as="foo">
	<f:if condition="{fooIteration.isFirst}">do something</f:if>
</f:for>

I don't see any downside of this, because "as" will always be unique in 
the template, as well as will be the iteration array using the "as" 
label as default prefix.

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list