I'd like to have a custom twig template for custom block plugins from my custom module.
My custom block HeaderText contains
public function build() {
return array(
'#title' => 'Test',
'#color' => $this->configuration['color'],
);
}
It is located in myplugin/src/Plugin/Block/HeaderText.php
I have a template block--HeaderText.html.twig located in myplugin/templates which only contains test code
<h1>{{ title }}</h1><p>{{ color }}</p>
However the template isn't used. Following a guide I also added the following to myplugin/myplugin.module
function myplugin_theme($existing, $type, $theme, $path){
return array('myplugin' =>
array(
'variables' => array(
'title' => 'Default title',
'color' => null
),
'template' => 'block--HeaderText'
)
);
}
Which did not work either. And even if the previous code did work, I have multiple plugins within that module and that code seems to apply to every block which I don't want to do. I'd like each block to have a unique template.