User login

Altering path and theme path of template files in Drupal 7 is just for make-believe?

Update: Issue posted. http://drupal.org/node/1028214

The goal is to use the book-variable.tpl.php (exactly like the book-variable.tpl.php is used, including how it gets overridden by themes) but without its preprocess function. Here's one fallback approach that should work, but doesn't, due to seeming weirdness in Drupal:

<?php
function dgd7glue_theme() {
  return array(
   
'dgd7glue_book_navigation' => array(
     
'variables' => array('book_link' => NULL),
     
'template' => 'book-navigation',
     
'path' => 'modules/book',
    ),
  );
}

function

dgd7glue_theme_registry_alter($theme_registry) {
 
debug($theme_registry['book_navigation']);
 
$theme_registry['dgd7glue_book_navigation']['path'] = $theme_registry['book_navigation']['path'];
 
$theme_registry['dgd7glue_book_navigation']['theme path'] = $theme_registry['book_navigation']['theme path'];
 
debug($theme_registry['dgd7glue_book_navigation']);
}

function

template_preprocess_dgd7glue_book_navigation(&$variables, $hook) {
 
$book_link = $variables['book_link'];
 
// Provide extra variables for themers. Not needed by default.
 
$variables['book_id'] = 'dgd7glue-nextprev';
 
$variables['book_title'] = t('Suggestions');
 
$variables['book_url'] = 'suggestions';
 
$variables['current_depth'] = 0;
 
$variables['tree'] = '';
 
$variables['has_links'] = TRUE;
 
// ... more
}
?>

Well this is totally bogus. We can see the two debug functions, and see the paths are being set successfully to the same thing. But we can see from the undefined index error below them that the book-navigation.tpl.php in core, not the one in the theme overriding it, is being called!

    * Debug:

      array (
        'template' => 'book-navigation',
        'path' => 'sites/default/themes/apress/templates',
        'type' => 'theme_engine',
        'theme path' => 'sites/default/themes/apress',
        'variables' => 
        array (
          'book_link' => NULL,
        ),
        'preprocess functions' => 
        array (
          0 => 'template_preprocess',
          1 => 'template_preprocess_book_navigation',
          2 => 'contextual_preprocess',
        ),
        'process functions' => 
        array (
          0 => 'template_process',
          1 => 'rdf_process',
        ),
      )

      in dgd7glue_theme_registry_alter() (line 77 of /home/ben/code/dgd7/drupal/sites/default/modules/dgd7glue/dgd7glue.module).
    * Debug:

      array (
        'variables' => 
        array (
          'book_link' => NULL,
        ),
        'template' => 'book-navigation',
        'path' => 'sites/default/themes/apress/templates',
        'type' => 'module',
        'theme path' => 'sites/default/themes/apress',
        'preprocess functions' => 
        array (
          0 => 'template_preprocess',
          1 => 'template_preprocess_dgd7glue_book_navigation',
          2 => 'contextual_preprocess',
        ),
        'process functions' => 
        array (
          0 => 'template_process',
          1 => 'rdf_process',
        ),
      )

      in dgd7glue_theme_registry_alter() (line 80 of /home/ben/code/dgd7/drupal/sites/default/modules/dgd7glue/dgd7glue.module).

Error

    * Notice: Undefined variable: prev_url in include() (line 39 of /home/ben/code/dgd7/drupal/modules/book/book-navigation.tpl.php).

Searched words: 
theme template path

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.