【问题标题】:Concatenate smarty variable with foreach将 smarty 变量与 foreach 连接起来
【发布时间】:2011-11-24 10:45:05
【问题描述】:

在 .tpl 文件中,我使用 smarty foreach 连接数组中的值,用管道“|”分隔:

{foreach from=$attachments item=attachment}{$attachment.file}|{/foreach}

这样写:test1.mp3|test2.mp3|test3.mp3|

现在...我需要将此结果作为变量传递到 href 链接中。 问题是我不能在 a href 标记中包含我的 foreach。

我还尝试将此结果分配给一个新的 smarty 变量,但不知道该怎么做。

任何帮助都会很棒。 谢谢。

【问题讨论】:

    标签: smarty


    【解决方案1】:

    你可以这样做:

    {assign var=result value=''}
    {foreach from=$attachments item=attachment}
        {assign var=temp value=$attachment.file}
        {assign var=result value=$result$temp|}
    {/foreach}
    

    【讨论】:

    • 这是我需要的东西。非常感谢!
    • 现在 concat 是 {assign var=result value="{$result}{$temp}"}
    猜你喜欢
    • 1970-01-01
    • 2014-12-13
    • 1970-01-01
    • 1970-01-01
    • 2011-05-13
    • 2014-03-19
    • 2016-09-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多