Does anyone have insight being able to use twig namespaces in templates?
https://twig.symfony.com/doc/2.x/api.html
https://symfony.com/doc/current/templating/namespaced_paths.html
I have been working on a plugin that hooks onTwigTemplatePaths and am able to addPath() to register a namespace. It also seem to return the paths in that namespace when i use getPaths(). But in grav I get:
Template "@atoms/test.twig" is not defined in "default2.html.twig" at line 1.
So it seems like grav isn’t registering or checking for @
as a namespace indicator.
public function onTwigTemplatePaths(Event $e)
{
$config = $this->config->get('plugins.twig-namespaces');
if (array_key_exists("namespaces", $config)) {
$namespaceLoader = new Twig_Loader_Filesystem(array());
foreach ($config["namespaces"] as $namespace => $item) {
foreach ($item["paths"] as $path) {
$namespaceLoader->addPath($path, $namespace);
}
}
}
}
then i have a plugin config file twig-namespaces.yaml
enabled: true
namespaces:
atoms:
paths:
- user/themes/pinterest-lab/templates/01-atoms
- user/themes/pinterest-lab/templates/01-atoms/test
I’m not sure if I my $namespaceLoader needs to be registered with the changes.
This is on similar work here: https://github.com/EvanLovely/plugin-twig-namespaces/blob/master/src/PatternLab/TwigNamespaces/PatternLabListener.php#L31
but not finding how to do addLoader()
and have it recognize the name space.