2016-10-17 27 views
0

如何定義一個數組數組並在for循環中輸出每個數字?如何定義數組的數組並輸出它?

我嘗試了這樣的:

<f:alias map="{numbers: [1,2,3,4,5,6]}"> 
    <f:for each="{numbers}" as="number"> 
     <p>{number}</p> 
    </f:for> 
    </f:alias> 

結果:

「地圖」 的參數是使用類型 「陣列」 註冊,但在視圖助手是類型 「string」 「TYPO3 \ CMS \ Fluid \ ViewHelpers \ AliasViewHelper」

而且是這樣的:

<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> 

結果:沒有輸出。

回答

3
<f:for each="{0:1, 1:2, 2:3, 3:4, 4:5, 5:6, 6:7}" as="foo">{foo}</f:for> 
0

試試這個:

<f:alias map="{numbers: {1,2,3,4,5,6}}"> 
    <f:for each="{numbers}" as="number"> 
     <p>{number}</p> 
    </f:for> 
</f:alias> 
+0

嗯,我得到'參數「映射」註冊類型「數組」,但是在視圖助手「TYPO3 \ CMS \ Fluid \ ViewHelpers \ AliasViewHelper」 – Black

+0

和這個「{1: 1,2:2,3:3,4:4,5:5,6:6}'?我只用這個詞,在這種情況下,我用一把鑰匙工作......我們在說v7.2.11? – webMan

+0

不,我得到同樣的錯誤。我使用v6.2.25 – Black

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 
  1. 確保已安裝擴展名爲VHS: Fluid ViewHelpers(擴展密鑰= vhs)。
  2. 請確保在部分中包含擴展名。

寫在上面:

<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

1

理想的解決方案當且僅當:

  • 您使用VHS 。
  • 你希望數字從0或1開始到最大;或使用這兩個起始索引計算的數字(TYPO3 8.0+支持原生流體中的數學表達式,早期版本需要VHS)。
  • 你想循環的數字,而不是消耗他們作爲一個數組。

這似乎正是你的使用案例...

那時,只有到那時,是下面在性能方面的理想解決方案,並最大限度地減少複雜性:

<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變量是不同的。部分或部分是表示這種確切類型的代碼的最有效方式,並且內聯語法在解析時效率最高。