Skip to content
Grav 2.1 is out: every page speaks Markdown. Read the announcement →

Overwrite AdminPlugin pages.html.twig

Started by Muut Archive 10 years ago · 3 replies · 795 views
10 years ago

Is it possible to overwrite the AdminPlugin pages.html.twig file with another plugin? I need a customized view of the pages without touching the AdminPlugin itself.

10 years ago

You can create a plugin that hooks in the onAdminTwigTemplatePaths event and provides a Twig templates folder, like

PHP
public static function getSubscribedEvents()
{
    return [
        'onPluginsInitialized' => ['onPluginsInitialized', 0],
        'onAdminTwigTemplatePaths' => ['onAdminTwigTemplatePaths', 0]
    ];
}

public function onAdminTwigTemplatePaths($event)
{
    $event['paths'] = [__DIR__ . '/admin/templates'];
}
10 years ago

Fix as per issue reported in https://github.com/getgrav/grav-plugin-admin/issues/999:

The above suggestion works only if a single plugin is overriding / providing an Admin twig template, which is not correct to assume.

As otherwise the last plugin that executes (lower priority), will have the final word.

Instead, use:

PHP
public function onAdminTwigTemplatePaths($event)
{
    $event['paths'] = array_merge($event['paths'], [__DIR__ . '/admin/templates']);
    return $event;
}

(adding to the paths, not overwriting the paths array on every plugin event execution) will do the correct job.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 2269 9 years ago
Archive · by Muut Archive, 9 years ago
2 1493 9 years ago
Archive · by Muut Archive, 9 years ago
2 4739 9 years ago
Archive · by Muut Archive, 9 years ago
1 3552 9 years ago
Archive · by Muut Archive, 9 years ago
3 1618 9 years ago