Replace 细枝:用模板include替换变量中的任意标记

Replace 细枝:用模板include替换变量中的任意标记,replace,symfony,template-engine,twig,Replace,Symfony,Template Engine,Twig,我希望用另一个模板的include替换从控制器传递到模板的变量中的令牌;概念上类似于: // 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 <

我希望用另一个模板的include替换从控制器传递到模板的变量中的令牌;概念上类似于:

// 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>
//控制器
$post->content=“这是一个终端用户写的短文。终端用户想要
要显示在此处的产品信息:%product\u info\u here%。完毕。

“; //小枝模板 {{post.content |替换({'%product\u info\u here%':include('product\u info.html.twig')}}
从细枝代码开始看,过滤器似乎无法访问其上下文,因此无法执行此操作。这个功能是否已经存在,如果不存在,在细枝体系结构中应该在哪里添加它

更新:


这是为了使最终用户能够确定应用程序应在何处注入部分。我把这个例子放在控制器里是为了简洁;实际上,文字标记将是最终用户输入的数据库中Post记录的一部分,并且Post内容将传递给Twig模板。我希望Twig模板解析令牌的post内容,并注入部分内容。

您能解释一下为什么要在控制器中放置模板吗?我认为以下措施也同样有效:

// Twig template
<div class="content">
  <p>Here's a short post. Product info: {% include('product_info.html.twig') %}</p>
</div>
//细枝模板
这是一篇短文。产品信息:{%include('Product_info.html.twig')%}


Ok。我不知道一个简单的方法,但您应该能够使用一个嵌入式控制器来实现这一点,该控制器将post.content作为参数传递。