1

I have written a small twig extension which deliever some functions.

This extension is bundled and I want to expose it as service of the bundle, so I have created the services.yml:

services:
    twig.job_action_extension:
        class: WebBundle\Template\JobActionExtension
        arguments: ["@translator"]
        tags:
            - { name: twig.extension }

But it seems that the extension is never exposed.
Running php app/console container:debug doesn't list my service.

Isn't it possible to register a twig extension as service like here?
Or do I need to create an extension under DependencyInjection like here if I want to contribute it as part of my bundle?

CSchulz
  • 10,882
  • 11
  • 60
  • 114

1 Answers1

1

I found my answer digging a little bit deeper.

I need to refer from the app/config/config.yml to the bundle services.yml (source).

If I want to do it automatically I really need the extension (source and the above referred extension).

So to answer my both questions:

  1. Yes it is possible to register an extension as service.
  2. You need the extension under DependencyInjection, if you want to autoload your extension without adjusting the app/config/config.yml.
CSchulz
  • 10,882
  • 11
  • 60
  • 114