【发布时间】:2017-02-13 05:01:32
【问题描述】:
假设我有自己的班级
<?php
class myClass {
public function myFunction(){
$template = $this->render('sometwigfile');
}
}
如果我想将 twig 文件加载到 NOT IN CONTROLLER 变量中该怎么办?
【问题讨论】:
假设我有自己的班级
<?php
class myClass {
public function myFunction(){
$template = $this->render('sometwigfile');
}
}
如果我想将 twig 文件加载到 NOT IN CONTROLLER 变量中该怎么办?
【问题讨论】:
只需使用:
$template = $this->renderView('whatever.html.twig')
render() 呈现完整的 HTTP 响应,包括标头,并返回一个 Response 对象,而 renderView() 只为您提供呈现的视图(即一些 HTML,在您的情况下)
【讨论】:
您可以注入templating 服务来渲染树枝模板并将其存储在变量中。
【讨论】: