Add CSS/JS to <head> from theme's modular page

I have a modular page which loads an external service (like Google Maps). I want the scripts of this service are only loaded when the modular page is used.

For example I have a modular page which shows a Google Maps of my company location, this map is only shown in About and Contact page, so the scripts of Google Maps are loaded only in these 2 pages.

If I use addInlineJs or addJs of Assets Manager and then use

{{ assets.js() }}

The scripts are shown where they called (in ).

There is an Assets plugin but it only works with *.md file. I want to add theses scripts in *.twig file.

Is there anyway I can do this?

You could extend your Block where the js is included in your modular Twig file or wherever you want. This of course presupposes to have your javascript files in a block in your base Twig or in whatever template your extending.

The problem is that modular twigs do not extend any base twig as they are just partials. The Assets plugin is a good solution, but just for markdown pages. Not sure how I’d do it