Is it possible to put a page-specific template inside the page/ folder, instead of polluting the template/ folder with a page-specific file? In other words: for a specific page how can I specify the location of the template instead of using the implicit template/ folder as the location?
This is not possible as the pages, are simply content. However, you can create a very simple plugin that contains a list of your ‘custom’ templates. I do this often while testing:
<?php
namespace Grav\Plugin;
use \Grav\Common\Plugin;
class TestingPlugin extends Plugin
{
public static function getSubscribedEvents()
{
return [
'onTwigTemplatePaths' => ['onTwigTemplatePaths', 0]
];
}
public function onTwigTemplatePaths()
{
$this->grav['twig']->twig_paths[] = __DIR__ . '/templates';
}
}
Then just create a templates/
folder in your plugin and drop any extra twig templates in there.
1 Like