Felix
Felix

Reputation: 5629

TYPO3 relation query - relational fluid rendering

I have a nested for loop in my fluid.

First for print all Parent Items.

the nested for loop should print all child elements related to the parent Item.

But the child loop dosn't work ... how should this look like?

I Have The Model Modul

and The Model Fach

and there is a 1:n Relation From Fach to Modul

And I Want to print a list like this:

Modul A - Fach 1 - Fach 2

Modul B - Fach ysd

Upvotes: 0

Views: 235

Answers (2)

lc_ik
lc_ik

Reputation: 124

For starters, if there is a relation between the objects "modules" and "fachs" there is no need to call two separate "findAll" methods. It is enougth to just call

$moduls = $this->modulRepository->findAll();

Extbase will get the relation between the two objects for you.

Your template should look like this (I don't know the property names, but you should get the context here):

<f:for each="{moduls}" as="modul"> 
    {module.name}
    <f:for each="{modul.fachs}" as="fach"> 
       {fach.fachname} 
    </f:for> 
</f:for>

The output of this should give the results you are looking for.

Regarding your filtering question. You should only get the data you from your database. So the best way to do this is your repository. Depending on the kind of filtering you want to do there might be different options. But in general I would always go for the repository first. And maybe do some additional stuff after that.

Upvotes: 1

Felix
Felix

Reputation: 5629

fluid Code:

`<f:for each="{moduls}" as="modul"> 
    <f:for each="{fachs}" as="fach"> 
       {fach.fachname} 
    </f:for> 
</f:for>`

Controller:

`public function listAction() {
    $moduls = $this->modulRepository->findAll();
    $fachs = $this->fachRepository->findAll();
    $this->view->assign('moduls', $moduls);
    $this->view->assign('fachs', $fachs);
}`

At the moment all Fach Objects were collected do I have to do the filtering with fluid or in controller?

Upvotes: 0

Related Questions