Skip to content

Commit

Permalink
Register theme prefixes as namespaces in twig (#2210)
Browse files Browse the repository at this point in the history
  • Loading branch information
WizKid authored and rhukster committed Nov 12, 2018
1 parent b9dc2ba commit d0b34d1
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions system/src/Grav/Common/Twig/Twig.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,28 @@ public function init()

$this->loader = new \Twig_Loader_Filesystem($this->twig_paths);

// Register all other prefixes as namespaces in twig
foreach ($locator->getPaths('theme') as $prefix => $_) {
if ($prefix === '') {
continue;
}

$twig_paths = [];

// handle language templates if available
if ($language->enabled()) {
$lang_templates = $locator->findResource('theme://'.$prefix.'templates/' . ($active_language ? $active_language : $language->getDefault()));
if ($lang_templates) {
$twig_paths[] = $lang_templates;
}
}

$twig_paths = array_merge($twig_paths, $locator->findResources('theme://'.$prefix.'templates'));

$namespace = trim($prefix, '/');
$this->loader->setPaths($twig_paths, $namespace);
}

$this->grav->fireEvent('onTwigLoader');

$this->loaderArray = new \Twig_Loader_Array([]);
Expand Down

0 comments on commit d0b34d1

Please sign in to comment.