Skip to content

Instantly share code, notes, and snippets.

@basvdheijden
Created June 25, 2016 09:27
Show Gist options
  • Save basvdheijden/d326609d41ca88801730cd2a473000f3 to your computer and use it in GitHub Desktop.
Save basvdheijden/d326609d41ca88801730cd2a473000f3 to your computer and use it in GitHub Desktop.
<?php
$render_array = [
// My render array full of items.
]
$render_context = new RenderContext();
$this->renderer->executeInRenderContext($render_context, function() use (&$render_array) {
$this->renderer->render($render_array);
});
$bubbleable_metadata = $render_context->pop();
$bubbleable_metadata->applyTo($render_array);
$content = $this->renderCache->getCacheableRenderArray($render_array);
$content['#cache']['tags'][] = 'rendered';
$response = new HtmlResponse($content, 200, [
'Content-Type' => 'text/html; charset=UTF-8',
]);
return $response;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment