In my Symfony2 bundle, I need to check if a function (an extension) is defined. More specifically, if the KnpMenuBundle is installed I use that one in my bundle, otherwise I will render the plugin myself.
I tried this, but this of course doesn't work:
{% if knp_menu_render() is defined %}
{# do something #}
{% else %}
{# do something else #}
{% endif %}
Is there a test/function/filter to check if a function is defined? If not, is there another way to check if the KnpMenuBundle is installed in the application?
Write a function in a Twig Extension which would check if bundle is enabled.
List of registered bundles is stored in the kernel.bundles
parameter.
Twig extensions are registered as services. This means you can pass any other service or a parameter to your extension:
<services>
<service id="acme.twig.acme_extension" class="Acme\DemoBundle\Twig\AcmeExtension">
<argument>%kernel.bundles%</argument>
<tag name="twig.extension" />
</service>
</services>
In your Twig function or filter you can later use a service or a parameter which you've passed to an extension.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With