How can I pass an array from a controller to a template?
You have to add the testmenu variable to the hook_theme implementation, like this:

function mdoner_custom_theme($existing, $type, $theme, $path) {
  return [
    'mdoner_custom_block' =&gt; [
      'variables' =&gt; [
        'title' =&gt; NULL,
        'testmenu' =&gt; [],
      ],
    ],
  ];
}


Then you have to pass it to the render array in your build() function like this:

return array(
  '#theme' =&gt; 'mdoner_custom_block',
  '#title' =&gt; 'MDoNER custom Block',
  '#testmenu' =&gt; $term_data, // #testmenu refers to the testmenu variable you set in hook_theme().
);


Now you should be able to iterate over the items in the testmenu variable like this:

{% for key, value in testmenu %}
  Key : {{ key }}
  Value : {{ value }}
{% endfor %}