Search code examples
symfonytwigtwig-extension

Multiple Twig_Extension in Symfony2


I want to register my custom Twig filters in separate bundle (to avoid having one huge file).

I have Yaml configurations in each bundle:

# services.yml
services:
    twig.extension.[BundleName]:
        class: Kuba\[BundleName]\Twig\AppExtension
        public: false
        tags:
            - { name: twig.extension }

Yet, all the time the last (lexicographically) extension overrides previous one.

How can I register more than one extension and if it's not possible what would be de best practise to split the code?


Solution

  • Twig extensions are identified by the string returned by getName() method. Is there a reason you have to return same string in all your twig extension!