@@ -43,83 +43,83 @@ Now, the variable ``ga_tracking`` is available in all Twig templates:
43
43
44
44
It's that easy!
45
45
46
- Referencing Services
47
- --------------------
46
+ Using Service Container Parameters
47
+ ----------------------------------
48
48
49
- Instead of using static values, you can also set the value to a service.
50
- Whenever the global variabele is accessed in the template, the service will be
51
- requested from the service container and you get access to that object.
49
+ You can also take advantage of the built-in :ref: `book-service-container-parameters `
50
+ system, which lets you isolate or reuse the value:
52
51
53
- This is done by prefixing the string with ``@ ``, which you already know from
54
- injecting a service:
52
+ .. code-block :: yaml
53
+
54
+ # app/config/parameters.yml
55
+ parameters :
56
+ ga_tracking : UA-xxxxx-x
55
57
56
58
.. configuration-block ::
57
59
58
60
.. code-block :: yaml
59
61
60
62
# app/config/config.yml
61
63
twig :
62
- # ...
63
64
globals :
64
- user_management : " @acme_user.user_management "
65
+ ga_tracking : " %ga_tracking% "
65
66
66
67
.. code-block :: xml
67
68
68
69
<!-- app/config/config.xml -->
69
70
<twig : config ...>
70
- <!-- ... -->
71
- <twig : global key =" user_management" >@acme_user.user_management</twig : global >
71
+ <twig : global key =" ga_tracking" >%ga_tracking%</twig : global >
72
72
</twig : config >
73
73
74
74
.. code-block :: php
75
75
76
76
// app/config/config.php
77
77
$container->loadFromExtension('twig', array(
78
- // ...
79
78
'globals' => array(
80
- 'user_management ' => '@acme_user.user_management ',
79
+ 'ga_tracking ' => '%ga_tracking% ',
81
80
),
82
81
));
83
82
84
- Using Service Container Parameters
85
- ----------------------------------
83
+ The same variable is available exactly as before.
86
84
87
- You can also take advantage of the built-in :ref: ` book-service-container-parameters `
88
- system, which lets you isolate or reuse the value:
85
+ Referencing Services
86
+ --------------------
89
87
90
- .. code-block :: yaml
88
+ Instead of using static values, you can also set the value to a service.
89
+ Whenever the global variabele is accessed in the template, the service will be
90
+ requested from the service container and you get access to that object.
91
91
92
- # app/config/parameters.yml
93
- parameters :
94
- ga_tracking : UA-xxxxx-x
92
+ This is done by prefixing the string with ``@ ``, which you already know from
93
+ injecting a service:
95
94
96
95
.. configuration-block ::
97
96
98
97
.. code-block :: yaml
99
98
100
99
# app/config/config.yml
101
100
twig :
101
+ # ...
102
102
globals :
103
- ga_tracking : " %ga_tracking% "
103
+ user_management : " @acme_user.user_management "
104
104
105
105
.. code-block :: xml
106
106
107
107
<!-- app/config/config.xml -->
108
108
<twig : config ...>
109
- <twig : global key =" ga_tracking" >%ga_tracking%</twig : global >
109
+ <!-- ... -->
110
+ <twig : global key =" user_management" >@acme_user.user_management</twig : global >
110
111
</twig : config >
111
112
112
113
.. code-block :: php
113
114
114
115
// app/config/config.php
115
116
$container->loadFromExtension('twig', array(
117
+ // ...
116
118
'globals' => array(
117
- 'ga_tracking ' => '%ga_tracking% ',
119
+ 'user_management ' => '@acme_user.user_management ',
118
120
),
119
121
));
120
122
121
- The same variable is available exactly as before.
122
-
123
123
Using a Twig Extension
124
124
----------------------
125
125
0 commit comments