2017-07-02 43 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