From 5186e13c3ffaddae587cae4f6595c38b3a1929ac Mon Sep 17 00:00:00 2001 From: Thomas Landauer Date: Wed, 31 Jan 2024 23:06:41 +0100 Subject: [PATCH] Moving `{% block importmap %}` *above* `{% block javascripts %}` Disclaimer: I'm not sure about this - especially I didn't check if `before_target` is actually doing what I want ;-) Here's the scenario I'm talking about: ```twig {# base.html.twig #} {% block javascripts %} {% block importmap %}{{ importmap('app') }}{% endblock %} // Here's some important JavaScript stuff that's needed on *every* page {% endblock %} ``` ```twig {# some_page.html.twig #} {% block importmap %}{{ importmap(['app', 'some_page']) }}{% endblock %} ``` Now how can I get the other important JavaScript onto `some_page`? IMO only by doing: % block javascripts %} {{ parent() }} {% endblock %} But this will also render the importmap *twice*. Right? My solution: Move `{% block importmap %}` **outside** of `{% block javascripts %}` If you merge this, the code block at https://symfony.com/doc/6.4/frontend/asset_mapper.html#installation would need to be updated again... :-) --- symfony/asset-mapper/6.4/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/symfony/asset-mapper/6.4/manifest.json b/symfony/asset-mapper/6.4/manifest.json index cebb7e683..1bbdf0c0d 100644 --- a/symfony/asset-mapper/6.4/manifest.json +++ b/symfony/asset-mapper/6.4/manifest.json @@ -16,7 +16,7 @@ { "file": "templates/base.html.twig", "content": "{% block importmap %}{{ importmap('app') }}{% endblock %}", - "position": "after_target", + "position": "before_target", "target": "{% block javascripts %}", "warn_if_missing": true }