【问题标题】:Smarty section loop an arraySmarty 部分循环一个数组
【发布时间】:2012-01-26 21:02:48
【问题描述】:

我正在尝试从 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
        )
    )
)

【问题讨论】:

    标签: smarty smarty3


    【解决方案1】:
    {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}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-20
      • 1970-01-01
      相关资源
      最近更新 更多