Closed aleksip closed 8 years ago
A solution for this would also resolve #8!
Do we want to enforce a convention that Twig extensions must have a Twig_Extensions
or TwigExtensions
as part of the class name to be loaded? We could look at declared/autoloaded classes and cherry pick out those ones that match that convention and use addExtension
.
Another much more complicated solution I thought of before the simpler idea above...
Is it worth doing a combo of either naming convention (a la PatternLabListener
) or composer.json
config to build out a listeners.json
style list of Twig extensions? The list would be modified at install of the extensions. Then that list of classes/extensions could be loaded in the Twig pattern loader.
I know we've had load order issues but it might be worth exploring the following changes:
./config/twig.json
. This way each pattern engine could determine this kind of thing on their own and I don't bake anything specific into core
../config/twig.json
and use that to load them.It seems like a slightly indirect solution. I think extensions would have to live in ./vendor
which may be a nonstarter for you all. The class needs to be available via the autoloader.
Just providing a starting point for ideas.
Nix that last idea. Going with #22 and #23 to see if that can address this problem.
The Twig Extensions Plugin shows a way that this can be done.
@dmolsen Excellent solution! This is so great, thanks!
Especially for use cases where many StarterKits use the same Twig extensions it would be good to be able to register a class implementing Twig_ExtensionInterface.