zenstruck / twig-service-bundle

Make functions, static methods, Symfony service methods available in your twig templates.
MIT License
10 stars 2 forks source link

Invokable Service Filters #2

Closed kbond closed 2 years ago

kbond commented 2 years ago
{{ 'something'|service('service-name') }}
{{ 'something'|service('service-name', 'extra', 'arg') }}
#[AsTwigService(alias: 'service-name')]
class PostService
{
    public function __invoke($value, $arg1 = null, $arg2 = null): string
    {
        $value; // 'something'
        $arg1; // null|'extra'
        $arg2; // null|'arg'
    }
}