Extension Programmierung

Cheat List Fluid

Displaying Lists with Fluid: the f:for ViewHelper

The f:for ViewHelper is normally used for displaying lists in fluid templates. It works like the "for each" funktion in php and allows additional parameter.

The iteration parameter makes some additional informations of the single data set available. An Example:

<f:for each="{array}" as ="single" iteration="iter">

   iter.index: consecutively numbered, start at 0
   iter.cycle: consecutively numbered, start at 1
   iter.total: Count all single Elements
   iter.isFirst: Return "1" at first Element
   iter.isLast: Return "1" at last Element
   iter.isEven: Return "1" is iter.cycle even number
   iter.isOdd: Return "1" if iter.cycle odd number

A zebrastyling for a table can easily achieved by using isEven / isOdd. You only need a inline if-ViewHelper for the css class.
Example:
<tr class="{f:if(condition:iterator.isOdd, then: 'class-grau', else: 'class-red')}">

Here a complete listing of the iteration parameter:

Return:

index cycle total isFirst isLast isEven isOdd Value
0 1 6 1 1 blau
1 2 6 1 rot
2 3 6 1 grün
3 4 6 1 gelb
4 5 6 1 schwarz
5 6 6 1 1 weiß

 

 

Further options of the Fluid f:for View Helper

reverse
Pass through the array backwards.
<f: for each="{objects}" as="single" reverse="1">

key
Added a key to the single data set:
<f: for each="{objects}" as="single" key="schluessel">

If we define the objects in the sample above like:

<f:alias map="{farben: {farbe_1: {ton: 'blau}, farbe_2: {ton: 'rot'} ....

The variable {schluessel} returns "farbe_1" inside the single data set.

ERROR: Content Element type "t3page_cetextimageright" has no rendering definition!

ERROR: Content Element type "t3page_cetextimageright" has no rendering definition!

ERROR: Content Element type "t3page_cecode" has no rendering definition!

Return:

index cycle total isFirst isLast isEven isOdd Value
0 1 6 1 1 blau
1 2 6 1 rot
2 3 6 1 grün
3 4 6 1 gelb
4 5 6 1 schwarz
5 6 6 1 1 weiß

 

 

ERROR: Content Element type "t3page_cetextimageright" has no rendering definition!

Weitere Artikel zu diesem Thema:

Kommentare

keine Kommentare vorhanden


Kommentar verfassen

Die Email Adresse wird nicht veröffentlicht.