我希望在foreach循环中使用项目的id获取var条件。 我想尝试(只是演示代码)如下,但它只是给我一个错误。
PHP
$this->smarty->assign(array(
'demo' => array(
'foo_bar' => 'succeed!',
'foo_seat' => 'succeed also!'
),
'bar' => 'bar',
'seat' => 'seat'
));
TPL
value="{$demo.foo_{$bar}}"
错误
Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "application/views/overzicht/selectie.tpl" on line 55 "{$demo.foo{$bar}}" - Unexpected "{", expected one of: "}"
谁有想法?
答案 0 :(得分:1)
试试这个
{assign var='property' value='foo_'|cat:$bar}
{$demo.$property}