Sometimes you want a variable to be accessible to all the templates you use. This is possible inside your app/config/config.yml file:
有時您希望有個變量能夠被您所使用的所有模闆通路,這可以在您app/config/config.yml檔案中設定:
# app/config/config.yml
twig:
# ...
globals:
ga_tracking: UA-xxxxx-x
Now, the variable ga_tracking is available in all Twig templates:
現在,變量ga_tracking可以被所有Twig模闆通路:
<p>Our google tracking code is: {{ ga_tracking }} </p>
; app/config/parameters.yml
[parameters]
ga_tracking: UA-xxxxx-x
ga_tracking: %ga_tracking%
The same variable is available exactly as before.
該變量同先前完全相同。
本文轉自 firehare 51CTO部落格,原文連結:http://blog.51cto.com/firehare/1008587,如需轉載請自行聯系原作者