The README has examples for instantiation for plain PHP and Symfony. The end of the page implies that it should work in Timber (under Wordpress), but it is not clear how to do this.
In plain PHP this is:
$loader = new \Twig\Loader\FilesystemLoader (__DIR__ . '/');
$twig = new \Twig\Environment ($loader);
$twig->addExtension (new \Parisek\Twig\AttributeExtension ());
In Timber, the Timber documentation states:
Twig has a \Twig\Environment class that you can use to extend Twig. One of the most common ways this is used is to add functions and filters to Twig. But it could also be used to add globals, extensions, and more.
Timber creates a \Twig\Environment object for you. You can use the timber/twig filter to access that object and extend Twig through it.
Timber further abstracts some of that functionality for you, so you can add functions or filters more easily.
It is not clear how to join these two together, i.e. get the attribute extension working in a Timber context.
Currently I create the Timber instance and the extension using:
require_once __DIR__ . '/vendor/autoload.php';
Timber\Timber::init ();
$loader = new \Twig\Loader\FilesystemLoader (__DIR__ . '/');
$twig = new \Twig\Environment ($loader);
$twig->addExtension (new \Parisek\Twig\AttributeExtension ());
but then get a fatal error, with: Unknown "create_attribute" function. There is presumably another missing registration step.
If the README could have an example instantiation that would be excellent and much appreciated.
(I am basically trying to get a template containing create_attribute().addClass(...) working and this seems to be a suitable route for that.)
Thank you for your kind work on this package.
The README has examples for instantiation for plain PHP and Symfony. The end of the page implies that it should work in Timber (under Wordpress), but it is not clear how to do this.
In plain PHP this is:
In Timber, the Timber documentation states:
It is not clear how to join these two together, i.e. get the attribute extension working in a Timber context.
Currently I create the Timber instance and the extension using:
but then get a fatal error, with:
Unknown "create_attribute" function. There is presumably another missing registration step.If the README could have an example instantiation that would be excellent and much appreciated.
(I am basically trying to get a template containing
create_attribute().addClass(...)working and this seems to be a suitable route for that.)Thank you for your kind work on this package.