Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Page specific template in page folder?

Started by Muut Archive 9 years ago · 1 replies · 438 views
9 years ago

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?

9 years ago

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
<?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

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1336 9 years ago
Archive · by Muut Archive, 9 years ago
2 926 9 years ago
Archive · by Muut Archive, 9 years ago
2 4056 9 years ago
Archive · by Muut Archive, 9 years ago
1 2941 9 years ago
Archive · by Muut Archive, 9 years ago
3 1112 9 years ago