I've faced with a problem of differentiating node templates for print-version (I'm using "print" module) and default node's default template.

I have a <div> which should be present in node--node_type.tpl.php but not in print-version (it contains info that is not required when viewing the page not on the display).

Currently I'm solving this with adding

<?php if (arg(0) == 'node'): ?>
<?php endif; ?>

But it seems to me that this kind an awkward way.

Can you offer any Drupal-alike and more convenient way to gain that?

Thank you.

2 Answers 2


load a print only CSS file and "display:none" for that div in it:

  • If I got you right, I'm supposed to add, let's say, 'notForPrintVersion' class to any desired div and when using a print template, provided by module, simply add declaration for that class?
    – DimG
    Oct 29, 2012 at 19:25
  • yep! that should work! I had pasted in how to include a print-only CSS file, but I guess it stripped it out.
    – jdu
    Oct 29, 2012 at 20:00
  • Ok, thank you for your response, for minimal differences between printer and notprinter pages it seems to be a good way to follow. I've just discovered another method, more flexible and one that can be used in any circumstances. I got this up into answer.
    – DimG
    Oct 29, 2012 at 21:37

Well, I've been inspecting the Print module code for a while and figured out the right solution. ( Mr. jdu's answer is still right too but if I have to build completely different templates for printer-friendly and default versions of nodes, it just won't be enough). So for those who may face this problem:

Print module creates a view mode called 'print'. When you get on /print/%nid page, a special function is fired that renders the node in 'print' view mode. Inspecting the code further we find that in 'print' view mode, in preprocess function, it adds the following theme_hook_suggestions:

if (($variables['elements']['#view_mode'] == 'print') && isset($variables['elements']['#print_format'])) {
  $type = $variables['elements']['#node']->type;
  $format = $variables['elements']['#print_format'];
  $nid = $variables['elements']['#node']->nid;

  $variables['theme_hook_suggestions'][] = "node__print";
  $variables['theme_hook_suggestions'][] = "node__print__{$format}";
  $variables['theme_hook_suggestions'][] = "node__print__{$format}__node__{$type}";
  $variables['theme_hook_suggestions'][] = "node__print__{$format}__node__{$nid}";

Therefore, all we need is create, in my case, "node--print--html--node--nbt_text.tpl.php" (underscores from suggestions turn into dashes, my content type is 'nbt_text').

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.