Skip to content
Grav 2.0 is officially stable. Read the announcement →
Themes & Styling

How to remove enqueued assets

first-time theme

Solved by pamtbaau View solution

Started by Mark 5 years ago · 4 replies · 491 views
5 years ago

Hi 👋,

in the parent theme I've got this line of code: {% do assets.add('theme://js/singlepagenav.min.js') %}

I'd like to remove this in my child theme.
Could you please tell me how to do this? 🙏

Thanks,
Mark

5 years ago

@mark-s, Never used it but maybe assets.removeJs() is what you are looking for:

See API on Asset Manager:

removeJs( string $key ) : \Grav\Common\$this
Removes an item from the JS array if set

Not sure how you are overriding the parent themes templates, but not adding the specific js file to the Asset Manager will do.

5 years ago

Thank you. Do you know, how to get the key for this function? Or what a key looks like? I have only got the MD5 hashed key.

5 years ago Solution

@mark-s, Although I've never used it, it sounds logical to me that the file reference used in assets.addJs('<file reference>', options), should also be used to remove it.

You can find it in the parent theme's template, or plugin's template.

👍 1
5 years ago

Thanks a lot! It's working.

TWIG
{% extends '@quark/modular.html.twig' %}

{% block javascripts %}
    {{ parent() }}
    {% do assets.removeJS('theme://js/singlepagenav.min.js') %}
{% endblock %}

Suggested topics

Topic Participants Replies Views Activity
Themes & Styling · by Pedro M, 2 months ago
4 226 2 months ago
Themes & Styling · by Ian, 2 months ago
3 119 2 months ago
Themes & Styling · by Norbert, 2 years ago
11 483 3 months ago
Themes & Styling · by Lukáš Findeis, 3 months ago
0 73 3 months ago
Themes & Styling · by Sebadamus, 4 months ago
5 152 3 months ago