Skip to content

[Templating] Adding AssetMapper to asset() function #21132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[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.
  • Loading branch information
ThomasLandauer authored Jun 24, 2025
commit 117be6865e342379601d7c7dba32d06bc1774b55
8 changes: 6 additions & 2 deletions templates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,12 @@ You can now use the ``asset()`` function:
{# the JS file lives at "public/bundles/acme/js/loader.js" #}
<script src="{{ asset('bundles/acme/js/loader.js') }}"></script>

The ``asset()`` function's main purpose is to make your application more portable.
If your application lives at the root of your host (e.g. ``https://example.com``),
Using the ``asset()`` function is recommended for two reasons:

* It automatically takes care of versioning your assets with
:doc:`Symfony's AssetMapper </frontend>`

* If your application lives at the root of your host (e.g. ``https://example.com``),
then the rendered path should be ``/images/logo.png``. But if your application
lives in a subdirectory (e.g. ``https://example.com/my_app``), each asset path
should render with the subdirectory (e.g. ``/my_app/images/logo.png``). The
Expand Down