Reputation: 20362
How can I define an array of numbers and output each number in a for loop?
I tried it like this:
<f:alias map="{numbers: [1,2,3,4,5,6]}">
<f:for each="{numbers}" as="number">
<p>{number}</p>
</f:for>
</f:alias>
Result:
The argument "map" was registered with type "array", but is of type "string" in view helper "TYPO3\CMS\Fluid\ViewHelpers\AliasViewHelper"
And like this:
<f:alias map="{v:iterator.explode(content: '1,2,3,4,5,6')}">
<f:for each="{content}" as="zahl">
<p>{zahl}</p>
</f:for>
</f:alias>
Result: No output.
Upvotes: 1
Views: 2040
Reputation: 1203
try this:
<f:alias map="{
numbers:{
1:1, 2:2, 3:3, 4:4, 5:5, 6:6
}}">
<f:for each="{numbers}" as="number">
<p>{number}</p>
</f:for>
</f:alias>
corrected after Clause Due remarks ...
Upvotes: 1
Reputation: 8723
Based on @webman's answer I tried the following in Typo3 V11 sucessully:
<f:alias map="{numbers: {0:1, 1:2, 2:3, 3:4, 4:5, 5:6}}">
<f:for each="{numbers}" as="number">
{number}
Upvotes: 0
Reputation: 4271
The ideal solution IF and only IF:
Which seems to be exactly your use case...
Then, and only then, is the following the ideal solution in terms of both performance and minimising complexity:
<v:iterator.loop count="6" iteration="iteration">
{iteration.index} starts at zero, {iteration.cycle} starts at one.
</v:iterator.loop>
Don't forget the following either:
{f:render(section: 'OtherSection', arguments: {iteration: iteration})
-> v:iterator.loop(count: 6, iteration: 'iteration')}
Which is the most efficient way of rendering a section X number of times
with only the iteration
variable being different. Sections or partials are the most efficient way to represent this exact type of code and the
inline syntax is the most efficient when parsing.
Upvotes: 2
Reputation: 1357
<f:for each="{0:1, 1:2, 2:3, 3:4, 4:5, 5:6, 6:7}" as="foo">{foo}</f:for>
Upvotes: 4
Reputation: 20362
I was able to solve it with this code:
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers"
v:schemaLocation="https://fluidtypo3.org/schemas/vhs-master.xsd">
<f:for each="{v:iterator.explode(content: '1,2,3,4,5,6')}" as="number">
<p>{number}</p>
</f:for>
Output:
1
2
3
4
5
6
VHS: Fluid ViewHelpers
(extension key = vhs).Write this at the top:
<html xmlns="http://www.w3.org/1999/xhtml" lang="en"
xmlns:v="http://typo3.org/ns/FluidTYPO3/Vhs/ViewHelpers"
v:schemaLocation="https://fluidtypo3.org/schemas/vhs-master.xsd">
I am using Typo3 v6.2.25
Upvotes: 0