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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

Archive

Overwrite AdminPlugin pages.html.twig

Started by Muut Archive 9 years ago · 3 replies · 670 views
9 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.

9 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'];
}
9 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 1296 9 years ago
Archive · by Muut Archive, 9 years ago
2 890 9 years ago
Archive · by Muut Archive, 9 years ago
2 4019 9 years ago
Archive · by Muut Archive, 9 years ago
1 2894 9 years ago
Archive · by Muut Archive, 9 years ago
3 1078 9 years ago