Skip to content

Commit 117be68

Browse files
[Templating] Adding AssetMapper to asset() function
Page: https://symfony.com/doc/6.4/templates.html#linking-to-css-javascript-and-image-assets There is another link to AssetMapper just one screen further down - maybe you want to merge them somehow: https://symfony.com/doc/6.4/templates.html#build-versioning-more-advanced-css-javascript-and-image-handling My point here is that the main advantage of the `asset()` function IMO is not the subdirectory scenario, but rather: If you *later* switch to AssetMapper, it saves you a lot of time if you've already used `asset()` everywhere.
1 parent 9ad93fa commit 117be68

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

templates.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,12 @@ You can now use the ``asset()`` function:
312312
{# the JS file lives at "public/bundles/acme/js/loader.js" #}
313313
<script src="{{ asset('bundles/acme/js/loader.js') }}"></script>
314314

315-
The ``asset()`` function's main purpose is to make your application more portable.
316-
If your application lives at the root of your host (e.g. ``https://example.com``),
315+
Using the ``asset()`` function is recommended for two reasons:
316+
317+
* It automatically takes care of versioning your assets with
318+
:doc:`Symfony's AssetMapper </frontend>`
319+
320+
* If your application lives at the root of your host (e.g. ``https://example.com``),
317321
then the rendered path should be ``/images/logo.png``. But if your application
318322
lives in a subdirectory (e.g. ``https://example.com/my_app``), each asset path
319323
should render with the subdirectory (e.g. ``/my_app/images/logo.png``). The

0 commit comments

Comments
 (0)