Reputation: 503
How can I use data coming from a custom ViewHelper in my Fluid Template.
I have made a custom ViewHelper that is returning data like this:
{cars: {
0: {car:'VW Golf V TDi 140 GT Sport DSG Van',price:'144900'},
1: {car:'Citroën C5 HDi Elegance',price:'168900'},
2: {car:'Seat Leon TSi Stylance',price:'173000'}
}}
And tried the code below, but it doesn't print anything inf the f:for
loop.
In FLuid I would like to run through this with a f:for loop.
But how do I get my data into the f:for
syntax?
<f:alias map="<car:CarInfo length="5" />">
<table cellpadding="5" cellspacing="0" border="2">
<f:for each="{cars}" as="car">
<tr>
<td>{car.car}</td>
<td>{car.price}</td>
</tr>
</f:for>
</table>
</f:alias>
Upvotes: 1
Views: 641
Reputation: 4271
Does your ViewHelper return an array or a JSON string? If this is a JSON string you cannot consume variables from it without the use of a third party ViewHelper or JSONVariableProvider (Fluid standalone and TYPO3v8+).
See: Parse an existing JSON string in fluid template?
If your ViewHelper does indeed return an array then the most efficient way to solve your use case is:
<f:for each="{car:carInfo(length: 5)}" as="car">...</f:for>
Upvotes: 0
Reputation: 4889
your <f:alias
code is broken. you need to use inline annotation, since you want to access the viewhelper inside an other viewhelper
https://wiki.typo3.org/Fluid_Inline_Notation
<f:alias map="{cars: '{car:CarInfo(length:\'5\')}'}">
Also did you include your namespace like this?
{namespace car=Vendor\Extension\ViewHelpers}
Upvotes: 1