tpl.php ausserhalb des theme ordners


Da habe ich ein wenig gegrübelt, aber jetzt klappt es. Ich habe ein Modul und möchte in diesem Modul eine tpl.php Datei definieren. Es macht natürlich wenig Sinn, wenn diese tpl Datei dann im theme Ordner sein muss. Hier wie man es macht:

<!–?php
/**

  • implementation of hook_preprocess_page
  • @param array $vars containing the variables that can be accessed in the page.tpl.php
    */
    function smarttravel_preprocess_page(&$vars) {
    if (arg(0) == 'smarttravel' || (arg(0) == 'smarttravel' && arg(1) == 'hotelinfo')) {
    $vars['template_files'][] = 'smarttravel';
    }
    }
    ?>

Jetzt wird nach einer Datei smarttravel.tpl.php gesucht, aber vorerst nur im Themes Ordner. Damit er auch noch an anderen Orten sucht muss der hook_theme_registry_alter implementiert werden:

<!–?php
/**

  • implementation of hook_registry_alter
  • let's make sure that we find the tpl.php files
  • @param $theme_registry
    */
    function smarttravel_theme_registry_alter(&$theme_registry){
    $theme_hook = 'page';
    $modulepath = drupal_get_path('module', 'smarttravel');
    array_unshift($theme_registry[$theme_hook]['theme paths'], $modulepath);
    }
    ?>

Damit dann am Schluss auch alles klappt muss natürlich noch der Cache geleert werden… that's it.