【问题标题】:SMARTY templating and variablesSMARTY 模板和变量
【发布时间】:2012-11-29 20:19:37
【问题描述】:

好的,所以我有这样的东西(我不能使用数组 - 我知道 - UGH):

{assign var="ctaText1" value="Join Now"}
{assign var="ctaText2" value="News"}
{assign var="ctaText3" value="Photos"}
{assign var="ctaText4" value="Blog!"}
{assign var="ctaText5" value="Store"}

{math equation='rand(1,5)'}

<div>{$ctaText}</div>

现在,我真正想要的是:

<div>{${$ctaText}{$equation}}</div>

显然,上述方法不起作用 - 我已经尝试过它和一些变体。但我想知道是否有办法做到这一点,以便我得到正确的随机变量并弹出 DIV 的文本值。

有什么想法吗?

【问题讨论】:

  • 在你看来为什么要这样做?

标签: templates variables smarty


【解决方案1】:

脏得要命,但它确实有效:

{assign var="ctaText1" value="Join Now"}
{assign var="ctaText2" value="News"}
{assign var="ctaText3" value="Photos"}
{assign var="ctaText4" value="Blog!"}
{assign var="ctaText5" value="Store"}

{php}
    echo $this->get_template_vars('ctaText'.rand(1,5));
{/php}

你可能会考虑重构整个变量赋值

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    • 1970-01-01
    • 1970-01-01
    • 2012-11-08
    • 2012-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多