Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 493a135

Browse filesBrowse files
committed
[symfony#2865] No change other than moving the parameters section above the services section per a suggestion by @stof, which I agree with (that parameters are more common to use as global Twig variables)
1 parent 17ae545 commit 493a135
Copy full SHA for 493a135

File tree

Expand file treeCollapse file tree

1 file changed

+26
-26
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+26
-26
lines changed

‎cookbook/templating/global_variables.rst

Copy file name to clipboardExpand all lines: cookbook/templating/global_variables.rst
+26-26Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -43,83 +43,83 @@ Now, the variable ``ga_tracking`` is available in all Twig templates:
4343

4444
It's that easy!
4545

46-
Referencing Services
47-
--------------------
46+
Using Service Container Parameters
47+
----------------------------------
4848

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:
5251

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
5557
5658
.. configuration-block::
5759

5860
.. code-block:: yaml
5961
6062
# app/config/config.yml
6163
twig:
62-
# ...
6364
globals:
64-
user_management: "@acme_user.user_management"
65+
ga_tracking: "%ga_tracking%"
6566
6667
.. code-block:: xml
6768
6869
<!-- app/config/config.xml -->
6970
<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>
7272
</twig:config>
7373
7474
.. code-block:: php
7575
7676
// app/config/config.php
7777
$container->loadFromExtension('twig', array(
78-
// ...
7978
'globals' => array(
80-
'user_management' => '@acme_user.user_management',
79+
'ga_tracking' => '%ga_tracking%',
8180
),
8281
));
8382
84-
Using Service Container Parameters
85-
----------------------------------
83+
The same variable is available exactly as before.
8684

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+
--------------------
8987

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.
9191

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:
9594

9695
.. configuration-block::
9796

9897
.. code-block:: yaml
9998
10099
# app/config/config.yml
101100
twig:
101+
# ...
102102
globals:
103-
ga_tracking: "%ga_tracking%"
103+
user_management: "@acme_user.user_management"
104104
105105
.. code-block:: xml
106106
107107
<!-- app/config/config.xml -->
108108
<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>
110111
</twig:config>
111112
112113
.. code-block:: php
113114
114115
// app/config/config.php
115116
$container->loadFromExtension('twig', array(
117+
// ...
116118
'globals' => array(
117-
'ga_tracking' => '%ga_tracking%',
119+
'user_management' => '@acme_user.user_management',
118120
),
119121
));
120122
121-
The same variable is available exactly as before.
122-
123123
Using a Twig Extension
124124
----------------------
125125

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.