Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Commit

Permalink
Fixed snippet twig loading.
Browse files Browse the repository at this point in the history
  • Loading branch information
seehat committed Aug 27, 2021
1 parent 01326da commit d4d69a2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "amteich/kirby-twig",
"description": "Twig templating support for Kirby CMS",
"type": "kirby-plugin",
"version": "4.1.3",
"version": "4.1.4",
"license": "MIT",
"authors": [
{
Expand Down
4 changes: 4 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
}
else {
$file = $kirby->extensions('snippets')[$name] ?? null;

if (Str::endsWith(strtolower($file), '.twig')) {
return twig($name . '.twig', $data);
}
}
}

Expand Down
8 changes: 8 additions & 0 deletions src/classes/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Kirby\Cms\App;
use Kirby\Toolkit\Html;
use Kirby\Toolkit\Tpl;
use Kirby\Toolkit\Str;

use \Twig\Environment as Twig_Environment;
use \Twig\TwigFunction as Twig_Function;
Expand Down Expand Up @@ -162,6 +163,13 @@ public function __construct(string $viewPath = '')
$loader->addPath($kirby->root('templates'));
}

// add plugin snippet paths
foreach ($kirby->extensions('snippets') as $snippetpath => $root) {
if (Str::endsWith(strtolower($root), '.twig')) {
$loader->addPath(str_replace($snippetpath . '.twig', '', $root));
}
}

// is viewpath in a plugin, add the pluginpath
if ($viewPath != $this->templateDir) {
$loader->addPath($viewPath);
Expand Down

0 comments on commit d4d69a2

Please sign in to comment.