From 9c9743e0b78557e44cd22d4d72dba0490c8129ae Mon Sep 17 00:00:00 2001 From: Ville Mattila Date: Tue, 21 Jan 2014 06:01:38 +0200 Subject: [PATCH] Added a section about using named assets --- cookbook/assetic/asset_management.rst | 73 +++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/cookbook/assetic/asset_management.rst b/cookbook/assetic/asset_management.rst index 48037824e45..9c0f05f12e3 100644 --- a/cookbook/assetic/asset_management.rst +++ b/cookbook/assetic/asset_management.rst @@ -242,6 +242,79 @@ combine third party assets, such as jQuery, with your own into a single file: +Using Named Assets +~~~~~~~~~~~~~~~~~~ + +AsseticBundle configuration directives allow you to define named asset sets. +You can do so by defining the input files, filters and output files in your +configuration under the ``assetic`` section. Read more in the +:doc:`assetic config reference `. + +.. configuration-block:: + + .. code-block:: yaml + + # app/config/config.yml + assetic: + assets: + jquery_and_ui: + inputs: + - '@AcmeFooBundle/Resources/public/js/thirdparty/jquery.js' + - '@AcmeFooBundle/Resources/public/js/thirdparty/jquery.ui.js' + + .. code-block:: xml + + + + + + + + @AcmeFooBundle/Resources/public/js/thirdparty/jquery.js + @AcmeFooBundle/Resources/public/js/thirdparty/jquery.ui.js + + + + + .. code-block:: php + + // app/config/config.php + $container->loadFromExtension('assetic', array( + 'assets' => array( + 'jquery_and_ui' => array( + 'inputs' => array( + '@AcmeFooBundle/Resources/public/js/thirdparty/jquery.js', + '@AcmeFooBundle/Resources/public/js/thirdparty/jquery.ui.js', + ), + ), + ), + ); + +After you have defined the named assets, you can reference them in your templates +with the ``@named_asset`` notation: + +.. configuration-block:: + + .. code-block:: html+jinja + + {% javascripts + '@jquery_and_ui' + '@AcmeFooBundle/Resources/public/js/*' %} + + {% endjavascripts %} + + .. code-block:: html+php + + javascripts( + array( + '@jquery_and_ui', + '@AcmeFooBundle/Resources/public/js/*', + ) + ) as $url): ?> + + + .. _cookbook-assetic-filters: Filters