如何获取配置参数在Symfony2树枝模板 [英] How to get config parameters in Symfony2 Twig Templates
本文介绍了如何获取配置参数在Symfony2树枝模板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Symfony2 Twig模板。我想输出此树枝模板中的config参数的值(版本号)。因此,我这样定义配置参数:
I have a Symfony2 Twig template. I want to output the value of a config parameter in this twig template (a version number). Therefore I defined the config parameter like this:
parameters:
app.version: 0.1.0
我可以在控制器中使用这个配置参数,但我不知道如何获得它在我的Twig模板。
I'm able to use this config parameter in Controllers but I have no clue how to get it in my Twig template.
推荐答案
轻松地,您可以在配置文件中定义:
Easily, you can define in your config file:
twig:
globals:
version: "0.1.0"
并在您的模板中访问它
{{ version }}
否则,它必须是一个带有Twig扩展名的方法来公开你的参数。
Otherwise it must be a way with an Twig extension to expose your parameters.
这篇关于如何获取配置参数在Symfony2树枝模板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文