Php 定义动态块名

Php 定义动态块名,php,smarty,block,smarty3,Php,Smarty,Block,Smarty3,我正在使用Smarty 3模板继承。我有以下问题: 这是父模板代码: {foreach from=$items_collection item=single_item name=foo} {block name="bar_{$smarty.foreach.foo.index}"} some html goes here that I need to make editable if required {/block} {/foreach} 在此之后,我通过以下方式扩展模板: {

我正在使用Smarty 3模板继承。我有以下问题:

这是父模板代码:

{foreach from=$items_collection item=single_item name=foo}
  {block name="bar_{$smarty.foreach.foo.index}"}
    some html goes here that I need to make editable if required
  {/block}
{/foreach}
在此之后,我通过以下方式扩展模板:

{extends file='path/to/template/file.tpl'}

{block name="bar_0"}random stuff{/block}
{block name="bar_1"}random stuff{block}
...
或任何其他动态生成的块名,它不会更改模板值。。。我在孩子身上得到的只是父母,但没有改变内容


是否有特殊的语法或任何其他技术来实现动态块名。

我认为没有。块不是作为变量保存,而是在显示时填充到模板中,而是编译一次,然后对于缓存的模板是静态的

模板继承是一个编译时过程,它创建一个 编译的模板文件。与基于 包含在{include}标记中的子模板确实有更好的性能 渲染时的性能


很难给出关于如何做你想做的事情的建议,因为你很模糊,但是你可能可以用一个

来做你想做的事情。是的,你是对的。我决定使用其他策略,使用{capture},然后将捕获内容占位符放在“父”模板中。