2013-02-28 79 views
0

我想在smarty中使用section命令來訪問數組。我想用smarty中的section命令迭代1-128,但主要的是循環必須是65.現在我可以使用$ smarty.section.foo.index訪問索引達到64。我想通過使用一個常數{$ lan.printer [$ smarty.section.foo.index] +64}來訪問index> 64中的值。但它不起作用。請幫我解決這個問題。在smarty中處理數組

我的代碼如下提前

{section name=foo start=1 loop=65 step=1} 
     {$lan.printer[$smarty.section.foo.index]} 
     {$lan.printer[$smarty.section.foo.index]+64} 
{/section} 

感謝。

回答

0

除了在代碼中明顯的錯別字,使用表達式作爲索引到一個數組,你需要首先分配給一個變量,因此它可以被引用:

{section name=foo start=1 loop=65 step=1} 
    {assign var=offsetIndex value=$smarty.section.foo.index+64} 
    {$lan.printer[$smarty.section.foo.index]} 
    {$lan.printer[$offsetIndex]} 
{/section}