Twig: How to find out if plugin is installed?

@pikim, Thanks for the context.

I want to contribute to a theme and added another plugin as dependency. The initial author wanted to make sure that everything also works without that plugin. Then we noticed, that just checking config.plugins.myplugin.enabled isn’t enough to be 100% sure.

  • When a plugin is added as a dependency to a theme, the plugin cannot be deleted using Admin. An error will be shown in Admin.
  • In case the plugin has been deleted manually and a config still exists, the following include statement will not throw an error and ignore the template.
    {% if config.plugins.myplugin.enabled %}
      {% include 'partials/myplugin.html.twig' ignore missing %}
    {% endif %}
    

I wouldn’t suggest to use my ugly suggestion, but instead rely on the above.