phpcssgrav

Exclude plugin css files from frontend assets in Grav


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?


Solution

  • 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