Smarty 部分循环数组

发布于 2024-12-29 05:33:06 字数 1323 浏览 1 评论 0原文

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

I am trying to generate a list of URLs from the following array in smarty 3. So for each loop I would need to output the [label] and [url]

At the moment I have:

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

This just outputs blank lines so it is half working just no text.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风透绣罗衣 2025-01-05 05:33:06
{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}
{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}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文