I'm looking to add a twig variable, which is set in a module, and render it in the html.html.twig template file for my theme.
In my module file I use the hook_preprocess_html() function where I render and set the twig variable like so:
function insusite_cta_bar_preprocess_html(&$variables) {
$output = \Drupal::theme()->render('insusite_cta_bar_actions', array('items' => $itemsOutput, 'panels' => $panelOutput));
$variables['cta_bar'] = $output;
}
Then in the html.html.twig template file in my themes folder I simply render the new cta_bar variable like so:
<!DOCTYPE html>
<html{{ html_attributes }}>
<head>
<head-placeholder token="{{ placeholder_token|raw }}">
<title>{{ head_title|safe_join(' | ') }}</title>
<css-placeholder token="{{ placeholder_token|raw }}">
<js-placeholder token="{{ placeholder_token|raw }}">
</head>
<body{{ attributes }}>
{{ page_top }}
{{ page }}
{{ page_bottom }}
{{ cta_bar }}
<js-bottom-placeholder token="{{ placeholder_token|raw }}">
</body>
</html>
This doesn't render anything at all.
However, if I add preprocess_html() function to my .theme file then it DOES work, problem is we're using drupal as a multi-site system so I'd have to find a way to add this in to every theme's html, is there a way to do this?