I've created a custom controller that pulls content from another node (the body). That content is defined in the node as Raw HTML.
public function page(Request $request): array {
$nid = $request->attributes->get('_nid');
$node_storage = $this->entityTypeManager()->getStorage('node');
$node = $node_storage->load($nid);
$content = $node->get('field_content')->value;
// Load Entity using passed NID from key.
$build = $content;
// Return new Response($build);
$render_array['snippet'] = [
'#theme' => 'webpart_snippet',
'#content' => $build,
'#prefix' => '<div class="webpart_outer_wrapper">',
'#suffix' => '</div>',
];
return $render_array;
}
I would like to render that content as if it were a native Symfony response. (e.g., correctly parse and HTML tags AND scripts)
In the node that I'm pulling in, I have, for example
<h1>This is text</h1>
and that is exactly what is showing on the page
It should be
This is text
I have defined a custom theme as well as twig template
/**
* Implements hook_theme().
* Declare a new theme
*/
function custom_webpart_snippet_theme() {
return [
'webpart_snippet' => [
'variables' => [
'content' => '',
],
],
];
}
$render_array['snippet']
? Shouldnt it just be $render_array['content'] and some renderable arrays?#type => markup, #markup => $build
?