Reputation: 3484
I have a working Fluid template file that looks like this:
<table class="my-extension" >
<tr>
<td>
<f:translate key="my-extension_domain_model_appointment.translator" />
</td>
<td>
{appointment.translator}
</td>
</tr>
<tr>
<td>
<f:translate key="my-extension_model_appointment.bringtranslator" />
</td>
<td>
{appointment.bringtranslator}
</td>
</tr>
</table>
In my model I got the class appointment
with the two properties translator
and bringtranslator
.
I want to iterate through all properties so in case I add another one I don't need to change anything in my html file. So I'm searching for something like this:
<f:for each="{appointmentproperty}" as="property">
<tr>
<td>
<f:translate key="my-extension_domain_model_appointment."+property />
</td>
<td>
{appointment.property}
</td>
</tr>
</f:for>
Can someone tell me how to do this with fluid? (btw. I'm still using the old 4.7.7 Version)
Upvotes: 0
Views: 1493
Reputation: 11
I think you search for something like this:
Here you can see, that you can give an array to the alias and then you can cycle through. Maybe you can come to the answer by this? Please comment, if you found the correct way.
<f:alias map="{employees: {0: {first_name: 'Stefan', city: 'Lindlar'},1: {first_name: 'Petra', city: 'Lindlar'},2: {first_name: 'Sascha', city: 'Remscheid'},3: {first_name: 'Patrick', city: 'Bonn'},4: {first_name: 'Sven', city: 'Gummersbach'},5: {first_name: 'Andrea', city: 'Wuppertal'}}}">
<table cellpadding="5" cellspacing="0" border="2">
<f:groupedFor each="{employees}" as="employeesByCity" groupBy="city" groupKey="city">
<tr>
<th colspan="2">{city}</th>
</tr>
<f:for each="{employeesByCity}" as="employee">
<tr>
<td>{employee.first_name}</td>
<td>{employee.city}</td>
</tr>
</f:for>
</f:groupedFor>
</table>
</f:alias>
Upvotes: 0
Reputation: 7016
You cannot do this out of the box. However if you access a property of your model in fluid ({model.property}
), under the hood the getProperty()
method is called.
So if you want some magic functionality that automatically expands your view if you model grows, you have to implement it.
I'll give you one example, but there are other ways to do this: You could add a method to your model:
/**
* @return array
*/
public function getPropertiesForTableView() {
return array(
'property1' => $this->getProperty1(),
'property2' => $this->getProperty2()
);
}
In your view, you can now access this new Getter Method:
<f:for each="{appointment.propertiesForTableView}" as="propertyValue" key='propertyName'>
<tr>
<td>
<f:translate key="my-extension_domain_model_appointment.{propertyName}" />
</td>
<td>
{propertyValue}
</td>
</tr>
</f:for>
You still have to "do" something if you add a property that should show in your view (adding the property to your array). But you dont need to adjust your template.
Upvotes: 1
Reputation: 1264
<f:for each="{appointments}" as="appointment">
<tr>
<td>
<f:translate key="my-extension_domain_model_appointment."{appointment.translator.uid} />
</td>
<td>
{appointment.bringtranslator}
</td>
</tr>
</f:for>
If your appointment object also has other objects, you can iterate them again in your iteration:
<f:for each="{appointments}" as="appointment">
{appointment.title}
<f:for each="{appointment.translators}" as="translator">
{translator.name}
</f:for>
</f:for>
Upvotes: 0