I have a node type that is usually viewed as a web page but the client requires that occasionally it is also printed out in hard copy.

There is quite a lot I can do with css and media queries for print media but I would ideally like greater control over the content through the page templates.

As far as I can tell, there are no special theme suggestions for print and that theme functions, hooks, and templates are not aware of the target medium, be it screen or print.

This is a Drupal 8 project and whereas there were some Drupal 7 modules for print that might have been worth investigating, there doesn't seem to be anything right now for D8.

I any case, getting control over the content in a twig template would be quite sufficient if only I could tell that it was being rendered for print rather than screen.

1 Answer 1


You cannot tell in drupal, if your page is going to be printed.

CSS and media queries is browser based. You deliver the same content (html) and the browser will generate different output for display and print.

If you want to do deliver a special print version, you have to provide a different url for this and link it on your page, for example a print button. You can then check in the twig for the special url and change the html.

  • Correct answer, just one note: If you provide a separate URL/route, then I'd actually use a different view mode there (e.g. print), that gives you an easy way to have different markup for the node if you want that and different formatter configuration (e.g. don't display tags as links).
    – Berdir
    Jan 7, 2016 at 21:41
  • I was thinking more of a query string like ?print=1 and then using the request in the template. That is what iainH was asking about. But your solution is of course a more complete one. With a print view mode you can configure this in the ui with no or minimal need for code, but you have to register to different routes.
    – 4uk4
    Jan 8, 2016 at 7:23

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.