Smarty部分循环一个数组

时间:2012-01-26 21:02:49

标签: smarty smarty3

我正在尝试从smarty 3中的以下数组生成一个URL列表。因此,对于每个循环,我需要输出[label]和[url]

目前我有:

{section name="foo" loop=$list.options}
{if $list.options[foo] != "names"}
    {$list.options[foo].label}
    {$list.options[foo].url}
{/if}
{/section}

这只输出空白行,所以只有一半没有文字。

[list] => Array (
    [type] => Table
    [name] => list
    [options] => Array (
        [names] => Array (
            [0] => id
            [1] => name
            [2] => url
            [3] => picture
            [4] => featured
        )
        [id] => Array (
            [enabled] => 1
            [label] => Id
            [url] => /admin/list/desc
        )
        [name] => Array (
            [enabled] => 0
            [label] => Name
            [url] => /admin/list/desc
        )
        [url] => Array (
            [enabled] => 0
            [label] => Uri
            [url] => /admin/list/desc
        )
        [picture] => Array (
            [enabled] => 0
            [label] => pciture
            [url] => /admin/list/desc
        )
        [featured] => Array (
            [enabled] => 0
            [label] => Featured
            [url] => /admin/content/list/desc
        )
    )
)

1 个答案:

答案 0 :(得分:0)

{section name="foo" loop=$list.options.names}
{if $list.options[foo] != "names"}
{assign var="row" value=$list.options[$list.options.names[foo]]}
        {$row.label}
        {$row.url}
{/if}
{/section}