Skip to content
● Meet Grav Guard: keep every Grav site you run secure and up to date, all from one place. Free for up to 3 sites. Read more β†’

How to remove enqueued assets

first-time theme

Solved by pamtbaau View solution

Started by Mark 5 years ago Β· 4 replies Β· 787 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 MarkP, 2 weeks ago
3 193 2 weeks ago
Themes & Styling Β· by TomW, 2 weeks ago
0 111 2 weeks ago
Themes & Styling Β· by themetman, 3 weeks ago
1 206 3 weeks ago
Themes & Styling Β· by AH, 1 month ago
1 324 3 weeks ago
Themes & Styling Β· by Bruno, 4 years ago
6 1523 3 weeks ago