0

I am creating a module to handle the reformatting of pages for printing in D7.

The structure of the URL is: /print/{nid}

I need to use a separate template than html.tpl.php as I have to get rid of our global header/footer but I still need our javascript and css to load.

I'm at a loss for how to correctly implement this.

I have created a menu_hook, otherwise I get a 404 page

I have tried using the $vars['theme_hook_suggestions'][] = 'html__print'; but I get no output

<?php
// print.module
function print_menu()
{
    $items  = array();

    $items['print/%node']   = array(
        'title' => '',
        'access arguments' => array('access content'),
        'page arguments' => array(1),
        'page callback' => 'print_process_print',
    );

    return $items;
}

function print_process_print(&$vars)
{
    error_log(__FUNCTION__.' called');
    error_log('node: '.var_export($vars, true));

    $vars['theme_hook_suggestions'][]  = 'html__print';

}

My template file is: sites/all/themes/zen/templates/html--print.tpl.php

Any help is greatly appreciated.

  • 1
    A page callback isn't the same thing as a theme preprocess function, what you're doing can't work...read through this, it should help – Clive Oct 23 '14 at 15:10
0

To create your own template override in a module is not the same as doing it in a theme. Look at Overriding a template file (.tpl.php) from a module.

Put this code in your module, and put the template file in a sub-directory 'templates'. Clear the cache.

function MODULE_preprocess_html(&$vars){
  $vars['theme_hook_suggestions'][]  = 'html__print';
}

function MODULE_theme_registry_alter(&$theme_registry) {
  $path = drupal_get_path('module', 'MODULE') . '/templates';
  $templates = drupal_find_theme_templates($theme_registry, '.tpl.php', $path);
  foreach($templates as &$template) {
    $template['type'] = 'module';
    $template['theme path'] = path_to_theme();
  }
  $theme_registry += $templates;
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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