Is it possible to have a modular template appear in the dropdown “Modular Template” field when its being included from a plugin? The only way I can get modular templates to work that are included by plugins, is to copy it from the plugin and to my ‘user/themes//modular’ directory. Screen Shot 2016-01-19 at 2
This is something we are actually working on now.
I managed to get this working by adding this into my plugin.php file:
<?php
namespace Grav\Plugin;
use \Grav\Common\Plugin;
use \Grav\Common\Grav;
use \Grav\Common\Page;
class MyPlugin extends Plugin
{
public static function getSubscribedEvents()
{
return [
'onPluginsInitialized' => ['onPluginsInitialized', 0],
'onGetPageTemplates' => ['onGetPageTemplates', 0]
];
}
public function onPluginsInitialized()
{
$this->active = true;
return;
}
public function onGetPageTemplates($event)
{
$types = $event->types;
$locator = Grav::instance()['locator'];
$types->scanBlueprints($locator->findResources('plugin://' . $this->name . '/blueprints'));
$types->scanTemplates($locator->findResources('plugin://' . $this->name . '/templates'));
}
}
---
Nice! I totally forgot about that event! I have added it to the list of things to document. Cheers!
Thanks, I also took the liberty of creating a boilerplate plugin in the future wishing to implement a modular component:
Is this something that is release worthy for the GPM? If so you can follow our documented release process
Not really, it’s more of a starting point so you can create reusable components, similar to lightslider.
My idea is to create a whole bunch of modular components such as sliders, accordions, views, page references, etc. that can be reused for different projects.
I quickly put together a component generator that uses grav cli to scaffold a new component. https://github.com/ellioseven/grav-plugin-modular-component-generator
Oh nice! We had actually planned to do something similar in the bin/grav
command.