Skip to content

Commit 527c8b6

Browse files
committed
feature symfony#3496 Added a section about using named assets (vmattila)
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes symfony#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
2 parents 1131247 + 9a60123 commit 527c8b6

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed

cookbook/assetic/asset_management.rst

+73
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,79 @@ combine third party assets, such as jQuery, with your own into a single file:
270270
<script src="<?php echo $view->escape($url) ?>"></script>
271271
<?php endforeach; ?>
272272
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+
273346
.. _cookbook-assetic-filters:
274347

275348
Filters

0 commit comments

Comments
 (0)