Skip to content

Commit

Permalink
feature #3496 Added a section about using named assets (vmattila)
Browse files Browse the repository at this point in the history
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #3496).

Discussion
----------

Added a section about using named assets

This PR will add a section about named assets to the asset management page.

| Q             | A
| ------------- | ---
| Doc fix?      | yes
| New docs?     | no
| Applies to    | all
| Fixed tickets |

Commits
-------

9c9743e Added a section about using named assets
  • Loading branch information
weaverryan committed Feb 4, 2014
2 parents 1131247 + 9a60123 commit 527c8b6
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions cookbook/assetic/asset_management.rst
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,79 @@ combine third party assets, such as jQuery, with your own into a single file:
<script src="<?php echo $view->escape($url) ?>"></script>
<?php endforeach; ?>
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 </reference/configuration/assetic>`.

.. 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
<!-- app/config/config.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:assetic="http://symfony.com/schema/dic/assetic">
<assetic:config>
<assetic:asset name="jquery_and_ui">
<assetic:input>@AcmeFooBundle/Resources/public/js/thirdparty/jquery.js</assetic:input>
<assetic:input>@AcmeFooBundle/Resources/public/js/thirdparty/jquery.ui.js</assetic:input>
</assetic:asset>
</assetic:config>
</container>
.. 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/*' %}
<script src="{{ asset_url }}"></script>
{% endjavascripts %}
.. code-block:: html+php

<?php foreach ($view['assetic']->javascripts(
array(
'@jquery_and_ui',
'@AcmeFooBundle/Resources/public/js/*',
)
) as $url): ?>
<script src="<?php echo $view->escape($url) ?>"></script>
<?php endforeach; ?>
.. _cookbook-assetic-filters:

Filters
Expand Down

0 comments on commit 527c8b6

Please sign in to comment.