I created a custom module with a page controller that returns a Symfony response (Symfony\Component\HttpFoundation\Response). The thing is I don't want to render my custom theme in this controller, just the theme_base template in this module.
$build = array( 'page' => array( '#theme' => 'theme_base', '#content' => $content, '#owner' => $owner, '#cache' => [ 'max-age' => 0, ], '#attached' => array( 'library' => array( 'my_module/library_name', ), ), ), ); $html = \Drupal::service('renderer')->renderRoot($build); $response = new Response(); $response->setContent($html); return $response; I tried attaching the module library to $build, or including it directly in Twig template but this doesn't seem to work.
Any ideas why this is not working? Or is there maybe another way I could do this?
Thanks!
renderRoot(). The libraries will be attached since drupal renders the renderable array$buildthat you return.