0

我想在我的 foreach 循环中使用项目的 id 获得一个条件变量。我想尝试的(只是演示代码)如下,但它只是给我一个错误。

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: "}"

谁有想法?

4

1 回答 1

1

试试这个

{assign var='property' value='foo_'|cat:$bar}

{$demo.$property}
于 2012-06-16T23:42:07.983 回答