Exclude plugin css files from frontend assets in Grav

197 views Asked by At

I don't want Grav to include the form-styles.css and the login.css on the frontend assets.

Upon research i found out, that they are included to the frontend assets by the login and form plugins, which can't be disabled.

Is there a way to exclude them from being added to the assets?

2

There are 2 answers

0
stckvrw On BEST ANSWER

First you have enqueue all your CSS assets at the end of the list with 'position': 'after' as option:

{% do assets.addCss('theme://css/your-own.css', {'position': 'after'}) %}

Now suppose you have three your own CSS assets

Then you can remove all other CSS assets from the assets.assets_css array using |slice filter:

{% set assets = array_key_value('assets_css', assets.assets_css|slice(-3), assets) %}

This line you can add after the end of the statement {% block stylesheets %} and before the statement {% block assets %}.

So the whole scheme would be:

{% block stylesheets %}
...
{% endblock %}

{% set assets = array_key_value('assets_css', assets.assets_css|slice(-3), assets) %}

{% block assets %}
...
{% endblock %}

If you have two your own CSS, then use |slice(-2) and so on

0
domena.online On

Try to use group for css

{% block stylesheets %}
    {% do assets.addCss('theme://css/style-1.css', { group: 'css' }) %}
    {% do assets.addCss('theme://css/style-2.css', { group: 'css' }) %}
    {% do assets.addCss('theme://css/style-3.css', { group: 'css' }) %}
{% endblock %}
{% block assets deferred %}
    {{ assets.css('css')|raw }}
{% endblock %}