In the Drupal 8 documentation I have found a way how to pass variable from controller to custom twig template
https://www.drupal.org/docs/8/theming/twig/create-custom-twig-templates-from-custom-module
test_twig.module
function test_twig_theme($existing, $type, $theme, $path) {
return [
'my_template' => [
'variables' => ['test_var' => NULL],
],
];
}
TestTwigController
class TestTwigController extends ControllerBase {
public function content() {
return [
'#theme' => 'my_template',
'#test_var' => $this->t('Test Value'),
];
}
}
But is there a way to pass variables from controller to already existing node template, for example to node--custom_content_type.html.twig