For my twig-D7 installation i've added a few extensions to twig, but where do you plan on having those in D8? Because they are not really a module so being in modules would be semanticaly incorrect and core/vendor would emply extentions being a part of core. Any plans on a /sites/all/vendor structure?
Hooking them in would become possible with something like
autoload_register('Myvendor',drupal_root . 'sites/all/myvendor);
twig()->addExtiension(new Myvendor_Twig_Extension());
BTW awesome seeing twig moving towards core acception :)
Comments
Comment #1
jenlamptonHi ReneB!
We've been thinking about where to put the new twig files, and for now we've been adding them to the stark theme. Eventually, I immagine they will replace the current .tpl.php files, so some in system, others in their own modules, and then each theme files in the themes, of course. Nothing's for sure yet though, so if you have more ideas please keep sharing them here :)
Comment #2
rene bakxThat makes sense indeed. So I guess all it would need is a method to get the initialized and registered twig engine and then a module could add an extension on init. Saves the option to create yet another hook :)
or if you need multiple
This way twig extensions become modules, and can live in their own environment. Dependencies could be managed trough the module system.
As for allowing themes to register extensions, somehow that doesn't feel okay to me. But then again, how often would a theme need to register an extension. A filter, now that's something I can imagine.
But that could use the same getTwig() method.
Comment #3
jenlamptonI think that makes sense, if you want the Twig engine to work differently, then you need a module. A theme is just supposed to be responsible for the output, generally speaking.
Comment #4
tlattimore commentedRe #2:
I totally agree. Adding an extension really steps over the bounds of what themes are intended for.
Would it be possible to adopt the 'libraries' (e.g sites/all/libraries) model for adding twig extensions? Though I am not sure twig extension constitute libraries. Is this what basically what you were implying in the original post for this thread, in regards to 'sites/all/vendor', ReneB?
Comment #5
jenlamptonwhat about sites/all/extensions? or are new people going to mix those up with modules?
maybe sites/all/themes/extensions?
Comment #6
jenlamptonmoving to active twig sandbox, also postponing for now.
Comment #7
podarok2jenlampton
sites/all/themes/extensions looks reasonable for me
possibly we have to make decision about core/themes/engine/twig/extensions for core-wide extensions