Entity print get variable in twig template 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(&amp;$vars) {
    $vars['field_name'] = $entity-&gt;get('field_name')-&gt;getValue();
  }


I also tried 

  function THEMENAME_template_preprocess_entity_print(&amp;$vars) {
    $vars['field_name'] = $entity-&gt;get('field_name')-&gt;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 ?
Looks like you need to review Entity Print in Drupal 8 again. I am using the Entity Print module and it works just fine. Here are some pointers I would recommend below. Your original post is regarding printing node variables in twig templates


On your content type, navigate to Manage Display-->Expand Custom Display Settings-->Enable PDF. This will create a PDF view mode (which is used for printing)
Create a twig template node--article--pdf.html.twig (replace article with machine name of your content type)
Update your_theme.info.yml and your_theme.libraries.yml as suggested in Entity Print in Drupal 8 so you can control the theme and assign a css file only for print
Copy and add entity-print.html.twig to your subtheme
Using node--article--pdf.html.twig, you can control whatever variable you need. However, I recommend you use the PDF view mode first to see what it can do for you. 


I have yet to use a preprocess function and you should only need that if you need additional processing. Using the PDF view mode, entity-print.html.twig and the node--article--pdf.html.twig templates you will be able to print as you need. 

Ultimately, you should use the PDF view mode so you can manage the PDF view mode (add classes, divs, order, add/hide/remove fields, etc.) through the UI. I have found that managing what fields are displayed through code can be cumbersome if you have a lot. The view mode can handle a lot of what you need, but you need to enable the PDf view mode first. 

Sample entity-print.html.twig

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
  &lt;meta charset="utf-8"&gt;
  &lt;title&gt;{{ title }}&lt;/title&gt;
  {{ entity_print_css }}
&lt;/head&gt;
&lt;body&gt;
  &lt;div class="optional_class"&gt;
      {{ content }}
  &lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;


Sample node--article--pdf.html.twig:

&lt;article class="optional_class_wrapper"&gt;
  {{ content.field_name }}
  {{ content.body }}
  {{ label }} 
  {{ content.field_name.0.value }}
&lt;/article&gt;