@@ -26,6 +26,9 @@ Configuration
26
26
* `field_name `
27
27
* `session `_
28
28
* `lifetime `_
29
+ * `templating `_
30
+ * `assets_version `_
31
+ * `assets_version_format `_
29
32
30
33
charset
31
34
~~~~~~~
@@ -100,6 +103,79 @@ lifetime
100
103
101
104
This determines the lifetime of the session - in seconds.
102
105
106
+ templating
107
+
108
+ .. _ref-framework-assets-version :
109
+
110
+ assets_version
111
+ ..............
112
+
113
+ **type **: ``string ``
114
+
115
+ This option is used to *bust * the cache on assets by globally adding a query
116
+ parameter to all rendered asset paths (e.g. ``/images/logo.png?v2 ``). This
117
+ applies only to assets rendered via the Twig ``asset `` function (or PHP equivalent)
118
+ as well as assets rendered with assetic.
119
+
120
+ For example, suppose you have the following:
121
+
122
+ .. configuration-block ::
123
+
124
+ .. code-block :: html+jinja
125
+
126
+ <img src="{{ asset('images/logo.png') }}" alt="Symfony!" />
127
+
128
+ .. code-block :: php
129
+
130
+ <img src =" <?php echo $view['assets']->getUrl('images/logo.png') ?>" alt =" Symfony!" />
131
+
132
+ By default, this will render a path to your image such as ``/images/logo.png ``.
133
+ Now, activate the ``assets_version `` option:
134
+
135
+ .. configuration-block ::
136
+
137
+ .. code-block :: yaml
138
+
139
+ # app/config/config.yml
140
+ framework :
141
+ # ...
142
+ templating : { engines: ['twig'], assets_version: v2 }
143
+
144
+ .. code-block :: xml
145
+
146
+ <!-- app/config/config.xml -->
147
+ <framework : templating assets-version =" v2" >
148
+ <framework : engine id =" twig" />
149
+ </framework : templating >
150
+
151
+ .. code-block :: php
152
+
153
+ // app/config/config.php
154
+ $container->loadFromExtension('framework', array(
155
+ // ...
156
+ 'templating' => array(
157
+ 'engines' => array('twig'),
158
+ 'assets_version' => 'v2',
159
+ ),
160
+ ));
161
+
162
+ Now, the same asset will be rendered as ``/images/logo.png?v2 `` If you use
163
+ this feature, you **must ** manually increment the ``assets_version `` value
164
+ before each deployment so that the query parameters change.
165
+
166
+ You can also control how the query string works via the `assets_version_format `_
167
+ option.
168
+
169
+ assets_version_format
170
+ .....................
171
+
172
+ **type **: ``string `` **default **: ``%s?%s ``
173
+
174
+ This option relates to the `assets_version `_ option and controls exactly
175
+ how the query string is constructed. For example, if ``assets_version_format ``
176
+ is set to ``%s?version=%s `` and ``assets_version `` is set to ``5 ``, rendered
177
+ assets would look like ``/images/logo.png?version=5 ``.
178
+
103
179
Full Default Configuration
104
180
--------------------------
105
181
@@ -161,7 +237,7 @@ Full Default Configuration
161
237
# templating configuration
162
238
templating :
163
239
assets_version : ~
164
- assets_version_format : ~
4DBC
240
+ assets_version_format : " %s?%s "
165
241
assets_base_urls :
166
242
http : []
167
243
ssl : []
0 commit comments