@@ -270,6 +270,79 @@ combine third party assets, such as jQuery, with your own into a single file:
270
270
<script src="<?php echo $view->escape($url) ?>"></script>
271
271
<?php endforeach; ?>
272
272
273
+ Using Named Assets
274
+ ~~~~~~~~~~~~~~~~~~
275
+
276
+ AsseticBundle configuration directives allow you to define named asset sets.
277
+ You can do so by defining the input files, filters and output files in your
278
+ configuration under the ``assetic `` section. Read more in the
279
+ :doc: `assetic config reference </reference/configuration/assetic >`.
280
+
281
+ .. configuration-block ::
282
+
283
+ .. code-block :: yaml
284
+
285
+ # app/config/config.yml
286
+ assetic :
287
+ assets :
288
+ jquery_and_ui :
289
+ inputs :
290
+ - ' @AcmeFooBundle/Resources/public/js/thirdparty/jquery.js'
291
+ - ' @AcmeFooBundle/Resources/public/js/thirdparty/jquery.ui.js'
292
+
293
+ .. code-block :: xml
294
+
295
+ <!-- app/config/config.xml -->
296
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
297
+ <container xmlns =" http://symfony.com/schema/dic/services"
298
+ xmlns : assetic =" http://symfony.com/schema/dic/assetic" >
299
+
300
+ <assetic : config >
301
+ <assetic : asset name =" jquery_and_ui" >
302
+ <assetic : input >@AcmeFooBundle/Resources/public/js/thirdparty/jquery.js</assetic : input >
303
+ <assetic : input >@AcmeFooBundle/Resources/public/js/thirdparty/jquery.ui.js</assetic : input >
304
+ </assetic : asset >
305
+ </assetic : config >
306
+ </container >
307
+
308
+ .. code-block :: php
309
+
310
+ // app/config/config.php
311
+ $container->loadFromExtension('assetic', array(
312
+ 'assets' => array(
313
+ 'jquery_and_ui' => array(
314
+ 'inputs' => array(
315
+ '@AcmeFooBundle/Resources/public/js/thirdparty/jquery.js',
316
+ '@AcmeFooBundle/Resources/public/js/thirdparty/jquery.ui.js',
317
+ ),
318
+ ),
319
+ ),
320
+ );
321
+
322
+ After you have defined the named assets, you can reference them in your templates
323
+ with the ``@named_asset `` notation:
324
+
325
+ .. configuration-block ::
326
+
327
+ .. code-block :: html+jinja
328
+
329
+ {% javascripts
330
+ '@jquery_and_ui'
331
+ '@AcmeFooBundle/Resources/public/js/*' %}
332
+ <script src="{{ asset_url }}"></script>
333
+ {% endjavascripts %}
334
+
335
+ .. code-block :: html+php
336
+
337
+ <?php foreach ($view['assetic']->javascripts(
338
+ array(
339
+ '@jquery_and_ui',
340
+ '@AcmeFooBundle/Resources/public/js/*',
341
+ )
342
+ ) as $url): ?>
343
+ <script src="<?php echo $view->escape($url) ?>"></script>
344
+ <?php endforeach; ?>
345
+
273
346
.. _cookbook-assetic-filters :
274
347
275
348
Filters
0 commit comments