[TYPO3-mvc] Fluid List Item Issue

Franz Koch typo3.RemoveForMessage at elements-net.de
Tue Dec 28 16:27:02 CET 2010


Hey Sebastiaan,

> The example:
>
> Department1
> Employee1
> Employee2
> Department2
> Employee3
> Employee4
> Employee5
> Etc.
>
> This is what im trying to get with LI's in html, but i dont have a clue
> how to get this out of the repository, and how to put it through Fluid
> and get the results i want. (See example)
>
> Any suggestions?

This depends on your data structure. Do your departments have a 
"employees" property where all employees of that department are 
assigned? If that's the case, do the following:

----------------------------------------------------------
In your Controller:
----------------------------------------------------------
// assuming you use a SVN version you can use the objectManager to 
create instances like below.
// if you're working with a TER version you should use 
t3lib_div::makeInstance instead (for now)
$departmentRepository = 
$this->objectManager->get('Tx_YourExt_Domain_Repository_DepartmentRepository');
$this->view->assign('departments', $departmentRepository->findAll());

----------------------------------------------------------
In Fluid:
----------------------------------------------------------
<dl class="employeeList">
<f:for each="{departments}" as="department">
<dt>{department.name}</dt>
<dd>
   <ul>
     <f:for each="{department.employees}" as="employee">
       <li>{employee.name}</li>
     </f:for>
   </ul>
</dd>
</f:for>
</dl>


For the case that only your employees know about the department they are 
working in you should have a look at the groupedForViewHelper which is 
first grouping your employees by department and then iterating over 
them, allowing the same logic like above.

If it's still unclear how to do, please give more information about your 
models and how those are related to each other.

Hope that helps.

-- 
kind regards,
Franz Koch


More information about the TYPO3-project-typo3v4mvc mailing list