【发布时间】:2012-03-15 02:40:18
【问题描述】:
我正在寻找从控制器传递给我的模板的变量中的标记替换为另一个模板的包含;概念上类似于:
// controller
$post->content = "<p>Here's a short post that an enduser wrote. The enduser wants
product info to appear here: %product_info_here%. Over and out.</p>";
// Twig template
<div class="content">
{{ post.content
| replace({ '%product_info_here%': include('product_info.html.twig') }) }}
</div>
从开始查看 Twig 代码开始,过滤器似乎无法访问其上下文,因此无法执行此操作。此功能是否已经存在,如果不存在,在 twig 体系结构中添加它的正确位置是什么?
更新:
这是为了使最终用户能够确定应用应在何处注入部分。为了简洁起见,我将示例放在控制器中;实际上,文字标记将成为最终用户输入的数据库中 Post 记录的一部分,并且帖子内容将传递给 Twig 模板。我希望 Twig 模板解析令牌的帖子内容,并注入部分内容。
【问题讨论】:
标签: replace symfony template-engine twig