Twig Template for a Custom Block Plugin 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' =&gt; 'Test',
        '#color' =&gt; $this-&gt;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

&lt;h1&gt;{{ title }}&lt;/h1&gt;&lt;p&gt;{{ color }}&lt;/p&gt;


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' =&gt;
        array(
            'variables' =&gt; array(
                'title' =&gt; 'Default title',
                'color' =&gt; null
                ), 
                'template' =&gt; '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.
This issue I ran into was I did not specify '#theme' in the Block Plugin.

I added

public function build() {
    return array(
        '#theme' =&gt; 'myplugin',
        '#title' =&gt; 'Test',
        '#color' =&gt; $this-&gt;configuration['color'],
        );
}


and it worked