Symfony3:将变量传递到FrameworkBundle:Template:Template



只想与社区进行双重检查,就没有机会将变量传递到路由文件中通过FrameworkBundle:template:template呈现的模板中,对吗?

感谢

它是按设计的:

但是,如果您正在渲染一个不需要任何数据传递到其中的简单模板,则可以通过使用内置的FrameworkBundle:Template:template控制器来避免完全创建控制器。https://symfony.com/doc/current/templating/render_without_controller.html

您可以看到,您只能传递三个缓存头选项和模板名称来渲染:

public function templateAction($template, $maxAge = null, $sharedAge = null, $private = null)
{
    ...
}

https://github.com/symfony/framework-bundle/blob/master/Controller/TemplateController.php#L37

因此,警告是:没有机会将自定义变量(不包括http缓存头选项)传递给通过FrameworkBundle:Template:template呈现的模板。

最新更新