I've looked through many similar questions and can't figure out what I'm missing. I have a custom module with a block...
/**
* Provides the 'Four Words' block
*
* @Block(
* id = "na_fourwords",
* admin_label = @Translation("Four Words Hero"),
* category = @Translation("Custom"),
* )
*/
class NAFourWordsBlock extends BlockBase {
public function build() {
return [
'#theme' => 'block__na_fourwords',
'#myvar' => 'TESTING',
'#attached' => ['library' => ['na_fourwords/na_fourwords']],
];
}
}
In my .module file:
function na_fourwords_theme($existing, $type, $theme, $path){
return [
'block__na_fourwords' => [
'variables' => [
'myvar' => NULL,
],
],
];
}
In my twig, {{ myvar }}
doesn't render. If I call {{ kint(elements.content) }}
, I get ...
elements.content => Array
(
[#theme] => block__na_fourwords
[#myvar] => TESTING
[#attached] => Array
(
[library] => Array
(
[0] => na_fourwords/na_fourwords
)
)
)
It looks like the data is getting passed through ... why am I unable to access it? I feel like there's something simple I'm overlooking.
Drupal 9.1.7 PHP 7.4.16
Thanks!