如何定义数字数组并输出for循环中的每个数字?
我试过这样:
<f:alias map="{numbers: [1,2,3,4,5,6]}">
<f:for each="{numbers}" as="number">
<p>{number}</p>
</f:for>
</f:alias>
结果:
论证&#34; map&#34;已注册类型&#34;数组&#34;,但类型为&#34;字符串&#34;在视图助手&#34; TYPO3 \ CMS \ Fluid \ ViewHelpers \ AliasViewHelper&#34;
就像这样:
<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>
结果:无输出。
答案 0 :(得分:4)
<f:for each="{0:1, 1:2, 2:3, 3:4, 4:5, 5:6, 6:7}" as="foo">{foo}</f:for>
答案 1 :(得分:1)
理想的解决方案IF和仅IF:
这似乎正是你的用例...
然后,只有这样,以下是在性能和最小化复杂性方面的理想解决方案:
<v:iterator.loop count="6" iteration="iteration">
{iteration.index} starts at zero, {iteration.cycle} starts at one.
</v:iterator.loop>
不要忘记以下内容:
{f:render(section: 'OtherSection', arguments: {iteration: iteration})
-> v:iterator.loop(count: 6, iteration: 'iteration')}
哪种方式最有效地呈现X部分的次数
只有iteration
变量不同。段或部分是表示这种确切类型的代码的最有效方式
在解析时,内联语法是最有效的。
答案 2 :(得分:0)
试试这个:
<f:alias map="{numbers: {1,2,3,4,5,6}}">
<f:for each="{numbers}" as="number">
<p>{number}</p>
</f:for>
</f:alias>
答案 3 :(得分:0)
我能用这段代码解决它:
<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>
<强>输出:强>
1
2
3
4
5
6
VHS: Fluid ViewHelpers
(扩展名为= vhs)。将其写在顶部:
<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">
我正在使用Typo3 v6.2.25