The filter "truncate" (of twig) does not exist in a view of a vendor bundle
Asked Answered
F

4

7

I am trying to use the bundle JMS Translation but I have this error. It is I guess because my version of twig is not the same the one of the bundle? What to do?

CRITICAL - Uncaught PHP Exception Twig_Error_Syntax: "The filter "truncate" does not exist in "...\vendor\jms\translation-bundle\JMS\TranslationBundle/Resources/views/Translate/messages.html.twig" at line 14" at ...\vendor\twig\twig\lib\Twig\ExpressionParser.php line 588 

Here is my requirement in composer.json:

 "require": {
        ...
        "twig/extensions": "~1.2.0",

Here is what is in the composer of JMS Translation:

"conflict": {
    "twig/twig": "1.10.2"
},
"require-dev": {
    "symfony/twig-bundle": "*",

Thanks in advance!

Fluent answered 26/2, 2015 at 15:55 Comment(0)
T
18

Save this in a txt file and use ever!

For Twig extensions (truncate & wordwrap)

composer require twig/extensions

after that you have two ways...

$twig->addExtension(new Twig_Extensions_Extension_Text());

Or include in services.yml

services:
    twig.extension.text:
            class: Twig_Extensions_Extension_Text
            tags:
                - { name: twig.extension }

For Symfony 4

in the file 'config/packages/twig_extensions.yaml'

Uncomment any lines below to activate that Twig extension
Twig\Extensions\ArrayExtension: null
Twig\Extensions\DateExtension: null
Twig\Extensions\IntlExtension: null
Twig\Extensions\TextExtension: null
Thao answered 2/12, 2015 at 18:22 Comment(0)
F
5

Although when I had installed it, it worked fine, now, it needs this:

services:
    twig.extension.text:
           class: Twig_Extensions_Extension_Text
           tags:
               - { name: twig.extension }
Fluent answered 26/2, 2015 at 16:17 Comment(1)
Addid this only changed the error message to be more general, saying The filter "translate" does not exist instead of .. exist in ... :-(Orbit
L
1

With symfony 4 you can use twig extra https://twig.symfony.com/doc/2.x/filters/u.html

Leyla answered 22/5, 2020 at 22:38 Comment(1)
Yes. composer require twig/string-extraStefansson
F
1

This solution works fine for me :

  1. $ composer require -W twig/extensions
  2. Uncomment any lines below to activate that Twig extension:
Twig\Extensions\ArrayExtension: null  
Twig\Extensions\DateExtension: null  
Twig\Extensions\IntlExtension: null  
Twig\Extensions\TextExtension: null 
Function answered 10/1, 2021 at 19:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.