From Controller to html.twig
Define the variables in your theme and the pass them as "#variable" = value. E.g. in YOUR_MODULE.module have something like:

function tb_megamenu_theme($existing, $type, $theme, $path) {
  $items['tb_megamenu'] = [
  'template' =&gt; 'tb-megamenu',
    'variables' =&gt; [
      'menu_name' =&gt; NULL,
      'content' =&gt; NULL,
      'section' =&gt; 'frontend',
      'block_theme' =&gt; \Drupal::config('system.theme')-&gt;get('default'),
    ],
  ];
}


In your controller use:

$render = [
  '#theme' =&gt; 'tb_megamenu',
  '#menu_name' =&gt; $this-&gt;getMenuName(),
  '#block_theme' =&gt; $this-&gt;getThemeName(),
  '#content' =&gt; $this-&gt;getContent(),
];