[FLOW3-general] nested lists

Bastian Waidelich bastian at typo3.org
Mon Aug 9 17:56:30 CEST 2010


Michael Stein wrote:

Hi Michael,

> I'm new to fluid.
> I have a database many object of type A, B, C
> I need a list
> - type A:
> -- obj 1
> -- obj 2
> -- obj 3
> - type B:
> -- obj 4
> -- obj 5
> -- obj 6
> - type C:
> -- obj 7
> -- obj 8
> -- obj 9

Have a look at the groupedFor ViewHelper. You can use it like:

<ul>
   <f:groupedFor each="{objects}" as="objectsOfThisType" groupBy="type" 
groupKey="type">
     <li>
       type {type}:
       <ul>
         <f:for each="{objectsOfThisType}" as="object">
           <li>{object.title}</li>
         </f:for>
       </ul>
     </li>
   </f:groupedFor>
</ul>

(untested)

You should also consider creating an intermediate model for the grouped 
representation by adding a method findAllGroupedByType() or similar to 
your repository that returns a nested result (either as more-dimensional 
array or preferably as a new domain object)

HTH,
Bastian



More information about the FLOW3-general mailing list