Correct way to alter markup as html within theme_preprocess_container? On my node edit form I've got a field widget that needs some information added to it. Before my alterations, the kint dump of $variables['children'] looks like:



However, after manually setting $variables['children'], the dump looks like:



Before alteration, html renders correctly. However, afterward it is all just rendered as a string with the HTML displaying on the page. 



I've tried using the create() method instead that's shown as available under: 



...but it doesn't do anything at all.

I've also instead tried changing $variables['element']['display']['#markup'], but that doesn't have any visible effect.
You can't modify a markup object, but you can use the create() method on a new markup object to replace the old one.

$variables['children'] = \Drupal\Core\Render\Markup::create('&lt;div&gt;Manually set&lt;/div&gt;');


By the way, you are modifying a twig debug message which won't be there in a production environment.