I have a View that has an enabled PDF version feature provided by the Print module (http://drupal.org/project/print). Its ok, but I'd like to tweak the output table with theming. According to the module documentation pdf output can be altered using these files:

- To modify the template of printer friendly pages, simply edit the
print.tpl.php or the css/print.css files.

- It is possible to set per-content-type and/or theme-specific templates
  which are searched for in the following order: 
   1. print_[format].node-[type].tpl.php in the theme directory
   2. print_[format].node-[type].tpl.php in the module directory 
   3. print_[format].tpl.php in the theme directory
   4. print_[format].tpl.php in the module directory 
   5. print.node-[type].tpl.php in the theme directory
   6. print.node-[type].tpl.php in the module directory 
   7. print.tpl.php in the theme directory
   8. print.tpl.php in the module directory (supplied by the module)

  format is either html, mail or pdf, and type is Drupal's node type (e.g.
  page, story, etc.)

My question is how to do the same when I use this module not on a specific node type but on a view? The views module's theming information table is unaware of the Print module so the possible theming *.tpl.php files are not shown there.

Supposing that the name of my view is foobar, what tpl.php file should I use?

(Views PDF module is not an option for me as it fails on my special characters..)

2 Answers 2


The .tpl file for a View with machine name "myview" would be views-view--myview--page.tpl.php. Following that convention and what the print module reports, I would try creating a .tpl called print.views-view--myview--page.tpl.php. Include <?php print $content; ?> in this file, clear Drupal's cache, visit the View's print page, and see if it registers.

Edit: Try and throw something like this in your theme's template.php file:

function mythemename_preprocess_node(&$vars) {
  // Something to make sure they're on your View.
  if (arg(0) == 'my_view' && arg(1) == 'print') {
    // Add a new template suggestion...
    $vars['theme_hook_suggestion'] = 'print__view_page'; // and then make a print--view-page.tpl.php file.
  • Tried print.views-view-myview--page.tpl.php, print.views-view-myview.tpl.php, print.views-view-myview--default.tpl.php, print.views-view-myview--.tpl.php but none of them worked.. I flushed the the cache between the calls.
    – jabal
    Commented Feb 3, 2012 at 13:16
  • I'm trying to figure out from the source how does it work, but I lack the necessary Drupal API knowledge.. :(
    – jabal
    Commented Feb 3, 2012 at 13:29
  • You can manually suggest the .tpl file to Drupal. I will throw some code in my answer. Commented Feb 3, 2012 at 15:14

I have achieved this implementing template_preprocess_print() function in my theme's template.php file.

function MYTHEME_preprocess_print(&$variables) {
  // Check if the page is not a node
  if (!isset($variables['node']->type)) {
    // Remove all other template suggestions, since they are for nodes, we don't need them.
    $variables['theme_hook_suggestions'] = array();
    // Check if the page is a view page
    $views_page = views_get_page_view();
    if (is_object($views_page)) {
      // Add template suggestions
      $variables['theme_hook_suggestions'][] = "print__view";
      $variables['theme_hook_suggestions'][] = "print__view__" . $views_page->name;
      $variables['theme_hook_suggestions'][] = "print__view__" . $views_page->name . '__' . $views_page->current_display;

With this code in template.php, after flushing the theme registry cache, you have following template suggestions:

  • print--view.tpl.php
  • print--view--VIEW-NAME.tpl.php
  • print--view--VIEW-NAME--DISPLAY-NAME.tpl.php

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.