Symfony 4 - Twig filter "trans" not detected

688 Views Asked by At

I have some twig files and inside I use the trans filter, unfortunately I get error like

Unknown "trans" filter.

when I run

bin/console debug:twig --filter trans

I can see the filter there, I see even my custom "trans2" filter, which gives me the same error that the trans2 filter is unknown.

I am running symfony 4 with api-platform installed.

If it helps, other filters like "raw" are working.

My twig.yaml config

twig:
    default_path: '%kernel.project_dir%/src/Resources/views'
    debug: '%kernel.debug%'
    strict_variables: '%kernel.debug%'

My whole symfony is autowired, I initialize twig using autowiring:

public function myAction(...., Twig $twig){
    $template = $twig->load(....);
    // then template render into variable which is sent as email body.
}

I have figured out that if I use $this->container->get("twig") instead of controller action argument, it works. Is there any way to make it somehow work with the controller action argument? I have tried to find some TwigInterface or TemplatingInterface that I thought might work but I did not find any.

0

There are 0 best solutions below