Cannot use drupal_set_messages in a custom controller module In a custom controller, when I try to use drupal_set_message() in a custom Module Controller it works only if I put : 

drupal_set_message('Test error', 'error');

return array(
   '#type' =&gt; 'markup',
   '#markup' =&gt; "Welcome",
);


=> the message is shown via {{ page.highlighted }}

If I put : 

drupal_set_message('Test error', 'error');

return array(
   '#type' =&gt; 'page',
   '#markup' =&gt; "Welcome",
);


It doesn't work... I need to put a type page to be able to inject custom variables. Does anybody can help me to understand how it works ? I try to read the docs and a Drupal 8 book but I really don't understand how that works.

Thanks !
You might want to try

return array(
  '#theme' =&gt; 'ctr',
  '#myvar' =&gt; 'myvalue',
);


And then define a hook_theme.

/**
 * Implements hook_theme().
 */
function ctr_theme($existing, $type, $theme, $path) {
  $variables = array(
    'ctr' =&gt; array(
      'template' =&gt; 'cntr',
      'variables' =&gt; array(
        'myvar' =&gt; 'defaultvalue',
      ),
    ),
  );
  return $variables;
}