I'm creating a module that will render a few nodes before getting back the result and print it as PDF. (I can't use wkhtmltopdf; I wish I could.)
So far, I managed to make my controller/action use the template I wanted, and anything I write in the template file is showed with die($html)
. However, I can't find any example of how to pass variables to the view; I tried a few things, but I got nothing, excepted 500 errors.
This is the code I am using.
public function nodeAction(NodeInterface $node) {
// Here, I define a variable named $responses that contains a lot of datas as arrays
$view_builder = \Drupal::entityTypeManager()->getViewBuilder('node');
$build = $view_builder->view($node, 'cnas_pdf');
$html = \Drupal::service('renderer')->renderPlain($build, ['var' => $response]);
// No error in this configuration, but "var" is nowhere to be found
die($html);
}