使用 Twig 进行模板化 - 永久访问我所有模板中的变量
我刚刚开始研究 Twig 我想知道如何完成以下任务。
我有一个变量 $logged_in ,我需要在网站的每个页面中访问该变量,我希望不是每次在数据数组中将其传递给树枝渲染器,而是有一种方法可以让我声明这个在某个地方,并且每个模板都可以访问它。
我是否需要构建一个扩展来完成此任务/或者甚至可能吗?我已经浏览了文档的每一页,但在尝试扩展此处描述的基本模板时遇到了麻烦...
这是正确的方法吗?
谢谢
I've just started looking into Twig and I'm wondering how I would accomplish the following.
I have a variable $logged_in that I need to have access to in every single page on my site, I was hoping that rather than passing this to the twig renderer every single time in the data array, there would be a way for me to declare this somewhere, and for every template to have access to it.
Do I need to build an extension to accomplish this / or is it even possible? I have looked through every page of the documentation but I'm having trouble having tried to extend the base template as described here...
Twig Documentation | Recipes | Making the Templates aware of the Context Dead link
Is this the right approach?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需阅读有关新功能的信息1.0RC 版本应该会有所帮助。
摘自博客文章:
全局:
PHP
模板
Just read about the new features in the 1.0RC release which should help.
Taken from the blogpost:
Globals:
PHP
Template