2017-07-02 62 views
0

我有这样的事情:Smarty的变量串联

<select class="form-control" name="activ"> 
{if {$smarty.session.admin['access']['pages:list:activ']} == '1'} 
    <option value="1">{#L_YES#}</option> 
    <option value="0">{#L_NO#}</option> 
{else} 
    <option value="0">{#L_NO#}</option> 
{/if} 
</select> 

我需要改变['pages:list:activ']['{$smarty.get.module}:list:activ']

我怎么能这样做?

回答

0

你这里有多种选择..

原因之一,PHP不会当您使用单引号解析变量。

所以

$a = 'string'; 
echo '$test with something'; 

将输出:

$test with something 

但是如果你使用:

$a = 'string'; 
echo "$test with something"; 

echo "{$test} with something"; 

它会输出:

string with something 

但对于Smarty的,如果您在名称中使用.->这是行不通的,因为你将不得不使用反引号周围的变量,像这样的(注意它周围的双引号) :

{if {$smarty.session.admin['access']["`$smarty.get.module`:list:activ"]} == '1'} 

欲了解更多信息,请参阅:Smarty Embedding Vars in Double Quotes


您还可以使用猫改性剂和分配concatena特德价值到变种:

{assign var = "moduleList" value = $smarty.get.module|cat:":list:activ"} 
{if {$smarty.session.admin['access'][$moduleList]} == '1'} 
+0

谢谢 - 它的工作:) – pat15