Adding blueprints to plugin pages

I am trying to create a plugin for managing a custom gallery. Using ‘onAdminMenu’ I add my Plugin to the Admin Menu, using ‘onTwigTemplatePaths’ I am able to display a custom page. I now want to add a Form which allows me to add a new album (basically one text input would be sufficient) but I can’t figure out how I can get my page to use a blueprint file. I have tried reverse engineering the flex-directory plugin but without success.

I hope someone can help me out.
Thank you!

  1. Create a blueprint for your page, say gallery.yaml and put in the fields you want, or extend the default page (read the docs on that here).
  2. Put that blueprint in a blueprints/ folder in your plugin folder.
  3. Register those blueprints in your plugin.php code by adding the following bits:
    use RocketTheme\Toolbox\Event\Event;

    public static function getSubscribedEvents()
        return [
            'onGetPageTemplates'   => ['onGetPageTemplates', 0]

     * Add blueprint directory to page templates.
    public function onGetPageTemplates(Event $event)
        $types = $event->types;
        $locator = Grav::instance()['locator'];
        $types->scanBlueprints($locator->findResource('plugin://' . $this->name . '/blueprints'));
        $types->scanTemplates($locator->findResource('plugin://' . $this->name . '/templates'));
        // ^^^ only necessary if you also have templates in your plugin

  1. Give your page that template, save and voilà! your fields should turn up in the Admin interface. :slight_smile:

Hope this helps! (Actually I think most of this is in the docs I referenced above, but it might still help you and others out by condensing those a bit. :wink: )

Thank you for your response! I feel stupid having missed that section of the docs :no_mouth:.
But still I am not able to get it to work correctly. I am going to describe my project in a bit more detail, maybe I am missing something obvious.

I have a Plugin called "gallery" with some extra directories in it:

└─── admin
│   └─── pages
│   │      └
│   │
│   └─── templates
│          └ gallery.html.twig
└─── blueprints
        └ gallery.yaml

Now in gallery.php:


   'onAdminMenu' => ['onAdminMenu', 0],

public function onAdminMenu() { 
   $this->grav['twig']->plugins_hooked_nav['Galerie'] = ['route' => $this->route, 'icon' => 'fa-image'];

I add a link to the admin menu, which redirects me to /admin/gallery. This is the page where I want my form to live.

I use:

public function onTwigTemplatePaths() {
   $this->grav['twig']->twig_paths[] = 'plugin://' . $this->route . '/admin/templates';

to add my template and correctly display the page I want.

From here on I have tried

  • adding your code
  • adding a “fontend form” to with

{% include "forms/form.html.twig" %}

         in my template

  • playing around with the blueprint and use many different ones to check if I have an error somewhere in there

But still I can’t get it to work.

It probably is just a stupid beginners mistake but I still hope someone can help me out with this one!

P.S. The final version of the plugin would display a list of all albums (children of the main gallery page), a button to edit them and a button to open a modal with a form which is used to create a new album