I'm attempting to pass some data from a block module into a template. I've found that I can make up a render array property and then access it in the template. Here is an example of my code:
class MyBlock extends BlockBase {
return [
'#firstname' => 'John',
'#lastname' => 'Doe',
];
}
I can access this data in the twig templeate by using:
{{ elements.myblock.content['#firstname'] }}
{{ elements.myblock.content['#lastname'] }}
Is this an acceptable means for passing data into a template? All the other examples I've found have the render arrays being picked up by a hook_theme function and then getting passed to the template. The method I show above seems simpler and I'm wondering if there is something problematic with doing it this way.
Thanks!