简体   繁体   中英

SMARTY templating and variables

Ok, so I have something like this (and I can't use arrays - I know - 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>

Now, what I actually want is something like:

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

Obviously, the above doesn't work - I've tried it and a few variations. But I'm wondering if there is a way to do it so I get the correct random variable and pop in the text value for the DIV.

Any thoughts?

dirty as hell but it works:

{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}

You might think about refactoring the whole variable assignment

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM