Registering Extensions
Usage
To register an extension, you need to add #[TwigExtension]
attribute to the
extension class, register it as a singleton and add it to the TwigExtension
collection:
app\MyTwigExtensions.phpphp<?php namespace Distantmagic\Resonance; use Distantmagic\Resonance\Attribute\Singleton; use Distantmagic\Resonance\Attribute\TwigExtension; use Twig\Extension\ExtensionInterface; use Twig\TwigFunction; #[Singleton(collection: SingletonCollection::TwigExtension)] #[TwigExtension] readonly class MyTwigExtension implements ExtensionInterface { // ... }