From 117be6865e342379601d7c7dba32d06bc1774b55 Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Tue, 24 Jun 2025 11:21:37 +0200 Subject: [PATCH] [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. --- templates.rst | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/templates.rst b/templates.rst index bc249024f05..5f6ddea8195 100644 --- a/templates.rst +++ b/templates.rst @@ -312,8 +312,12 @@ You can now use the ``asset()`` function: {# the JS file lives at "public/bundles/acme/js/loader.js" #} -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 ` + +* 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