将参数传递给所有视图 [英] Pass parameter to all views
问题描述
我想显示所有Twig视图的用户名/最后连接日期/时间和一些其他信息(所有这些都扩展了一个常见的Twig布局)。
我如何实现,而不必显式地将每个控制器的参数传递给每个视图?
我必须创建一个Twig扩展,或者调用一个控制器/操作,将使用渲染从布局检索用户名/连接/其他信息?
如果可能,我想要一个更简单的解决方案。
用户可以作为预定义的全局变量访问,请查看此,如果您想在所有模板中重复使用相同的模板片段,请查看 include 标签。
I want to display the user name/last connection date/time and some other info on all of my Twig views (which all extend a common Twig layout).
How can I achieve that without having to explicitely pass those parameters from each controller to each view ?
Do I have to create a Twig extension, or make a call to a controller/action that will retrieve username/connection/other info from the layout using render?
I'd like a simpler solution if possible.
User is accessible as a predefined global variable, take a look at this, and if you want to reuse the same template fragment in all your templates take a look at the include tag.
这篇关于将参数传递给所有视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!