phptwiggrav

How can i check if a plugin is enabled on grav cms / twig if plugin contain dash inside its name?


I build a theme for Grav cms and i need to check if a plugin is enabled or not using the code below inside my twig template:

{% if config.plugins.star-ratings.enabled %}
//Then do this and that...
{% endif %}

The problem is that this code gives error because there is the dash inside the plugin name:

star-ratings

Which would be the right syntax in twig? I also tried:

{% if config.plugins.["star-ratings"].enabled %}

but still doesn't work


Solution

  • Have you tried (without the dot):

    {% if config.plugins["star-ratings"].enabled %}
        enabled
    {% else %}
        disabled
    {% endif %}
    

    working example