I'm using entity print and I would like to get node variables in my twig template, so I can call them like {{ content.field_name }}.
I tried using a preprocess function but I'm not sure I'm doing things well.
Assuming I have a twig template called entity-print.html.twig, here the preprocess functions I tried :
function THEMENAME_template_preprocess_entity_print(&$vars) {
$vars['field_name'] = $entity->get('field_name')->getValue();
}
I also tried
function THEMENAME_template_preprocess_entity_print(&$vars) {
$vars['field_name'] = $entity->get('field_name')->value;
}
I'm calling field_name with all of this twig variable for debugging purpose :
1 {{ content.field_name.0 }}
2 {{ content.field_name.value }}
3 {{ content.field_name.0.value }}
4 {{ field_name.content }}
5 {{ content.field_name[0] }}
6 {{ node.field_name.value }}
Nothing come. What am I doing wrong ? Do I have to make a custom module ?
$entity
is not defined.$entity = \Drupal::routeMatch()->getParameter('node');
$entity = \Drupal::routeMatch()->getParameter('node'); $vars['field_make'] = $entity->get('field_make')->getvalue();
I get page error with "website is currently unable to handle this request."node--[type].html.twig
ornode--[nodeid].html.twig
? Why did you createentity-print.html.twig
?