Twig Gravatar on Symfony 4

I’m a newbie on Symfony and I’m having a problem to integrate the ‘ry167/twig-gravatar’ package on my project.

First, I did :

$ composer require ry167/twig-gravatar 3.0.0

And after I modified my services.yaml, which looks like this :

        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
    resource: '../src/*'
    exclude: '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}'

    resource: '../src/Controller'
    tags: ['controller.service_arguments']

    class: TwigGravatar
        $default: ~         e.g. 'monsterid'
        $size: ~            e.g. 50
        $filterPrefix: ~    e.g. 'foo'
        $rating: ~          e.g. 'x'
        $useHttps: true
        - { name: twig.extension }

And finally, I have this on my view:

<p>{{ '[email protected]'|grAvatar }}</p>

But I got this error:

Invalid service “twig.extension.gravatar”: class “Twig_Extension” not found while loading “TwigGravatar”

Any ideas? I can’t understand where my problem comes from…

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 1

Your email address will not be published. Required fields are marked *

Stefanie Drost

Stefanie Drost

I had the same problem. I ended up writing my own Twig Extension class which extends the TwigGravatar Extension Class.

Then you can remove the service definition. The extension will automatically be loaded.

Greets Stefanie