I have a views that I am printing to PDF using Entity Print. The views is a combination of several entities and as such cannot directly utilize the instruction in the "Modify entity content" section of the documentation:

To modify the content of your entity, you create a twig template using the 'pdf' view mode name (e.g. node--article--pdf.html.twig). In this template you can modify the markup as you normally do with other view modes using {{ content.field_example }} or {{ node.field_example }}.

See screenshot of the view:

enter image description here I tried this twig template suggestion entity-print--views--machine_name--pdf.html and template variables like {{ content.field_bright_news }} (where the name of one of the fields of a referred entity of the view is field_bright_news) but that doesn't seem to work except I may be missing something.

Is the stated instruction in the documentation applicable to views as well or it's solely meant for actual entities. If yes, what is the correct template and variable pattern for this scenario ?

1 Answer 1


I don't think that your template suggestion is correct in this case, so {{content.field_bright_news}} may not work.

A few things I can clarify for you are as follows:

{{content.field_bright_news}} - this variable is only available in the template of the content type containing that field, it cannot be used in the view template.

For your quote, it is missing the following:

By default this module only installs the PDF view mode for Nodes. If you have any custom entities on your Drupal site and want to hide the "View PDF" link on those, you must first create a PDF view mode for the entity type. To do this navigate to "admin / structure / display-modes / view" and click on "Add view mode". In the list click the entity type for which you would like to create the PDF view mode. You'll now be asked to name the view mode, you can name it whatever you like but make sure the machine name is just "pdf", which will be automatically prefixed with the entity name. You can now follow the steps in the previous paragraphs for your custom entity.

That is, you must create a display mode for that content type to have a template suggesting as the form


And that means, {{content.field_bright_news}} can be used in the template suggested above.

  • You clearly haven't used the module before and my question is not about node, which is what the section of the document referred to. My question is whether or not and how the stated instruction is applicable to views. It has it nuances that's slightly different from the typical theming approach.
    – Ojchris
    Jan 18, 2021 at 5:53
  • I need a little more clarification. Is what you need to use is the field_bright_news of each node in the view?
    – mr.Thi
    Jan 18, 2021 at 15:44
  • The view has fields from several entities's, including custom content type, drupal commerce entities including order, order item and invoice.
    – Ojchris
    Jan 19, 2021 at 14:04
  • your template suggestion is come from the line 75 of this file: entity_print/src/PrintBuilder.php. And the variable content is come from line #77 '#content' => $content with $content = $renderer->render([$entity]);. So if you want to use {{ content. child_variable }} , you need to dump that variable to check which one can be use. Does it have {{content.field_bright_news}}?
    – mr.Thi
    Jan 19, 2021 at 15:57
  • 1
    If you are not rendering the Content in the view, but using fields, it won't pick up this template. You'd have to use the Content style and the PDF view mode which is what I think the docs are saying.
    – Kevin
    Jan 21, 2021 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.