@@ -242,6 +242,79 @@ combine third party assets, such as jQuery, with your own into a single file:
242
242
<script src="<?php echo $view->escape($url) ?>"></script>
243
243
<?php endforeach; ?>
244
244
245
+ Using Named Assets
246
+ ~~~~~~~~~~~~~~~~~~
247
+
248
+ AsseticBundle configuration directives allow you to define named asset sets.
249
+ You can do so by defining the input files, filters and output files in your
250
+ configuration under the ``assetic `` section. Read more in the
251
+ :doc: `assetic config reference </reference/configuration/assetic >`.
252
+
253
+ .. configuration-block ::
254
+
255
+ .. code-block :: yaml
256
+
257
+ # app/config/config.yml
258
+ assetic :
259
+ assets :
260
+ jquery_and_ui :
261
+ inputs :
262
+ - ' @AcmeFooBundle/Resources/public/js/thirdparty/jquery.js'
263
+ - ' @AcmeFooBundle/Resources/public/js/thirdparty/jquery.ui.js'
264
+
265
+ .. code-block :: xml
266
+
267
+ <!-- app/config/config.xml -->
268
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
269
+ <container xmlns =" http://symfony.com/schema/dic/services"
270
+ xmlns : assetic =" http://symfony.com/schema/dic/assetic" >
271
+
272
+ <assetic : config >
273
+ <assetic : asset name =" jquery_and_ui" >
274
+ <assetic : input >@AcmeFooBundle/Resources/public/js/thirdparty/jquery.js</assetic : input >
275
+ <assetic : input >@AcmeFooBundle/Resources/public/js/thirdparty/jquery.ui.js</assetic : input >
276
+ </assetic : asset >
277
+ </assetic : config >
278
+ </container >
279
+
280
+ .. code-block :: php
281
+
282
+ // app/config/config.php
283
+ $container->loadFromExtension('assetic', array(
284
+ 'assets' => array(
285
+ 'jquery_and_ui' => array(
286
+ 'inputs' => array(
287
+ '@AcmeFooBundle/Resources/public/js/thirdparty/jquery.js',
288
+ '@AcmeFooBundle/Resources/public/js/thirdparty/jquery.ui.js',
289
+ ),
290
+ ),
291
+ ),
292
+ );
293
+
294
+ After you have defined the named assets, you can reference them in your templates
295
+ with the ``@named_asset `` notation:
296
+
297
+ .. configuration-block ::
298
+
299
+ .. code-block :: html+jinja
300
+
301
+ {% javascripts
302
+ '@jquery_and_ui'
303
+ '@AcmeFooBundle/Resources/public/js/*' %}
304
+ <script src="{{ asset_url }}"></script>
305
+ {% endjavascripts %}
306
+
307
+ .. code-block :: html+php
308
+
309
+ <?php foreach ($view['assetic']->javascripts(
310
+ array(
311
+ '@jquery_and_ui',
312
+ '@AcmeFooBundle/Resources/public/js/*',
313
+ )
314
+ ) as $url): ?>
315
+ <script src="<?php echo $view->escape($url) ?>"></script>
316
+ <?php endforeach; ?>
317
+
245
318
.. _cookbook-assetic-filters :
246
319
247
320
Filters
0 commit comments