Is this acceptable for passing data from a module to a template? 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' =&gt; 'John',
        '#lastname' =&gt; '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!
If you pass the variables like the following:

class MyBlock extends BlockBase {
  public function build() {
    return [
      '#firstname' =&gt; 'John',
      '#lastname' =&gt; 'Doe',
    ];
  }
}


You can access to your variables #firstname and #lastname like:

{{ content['#firstname'] }}
{{ content['#lastname'] }}