tags:

views:

480

answers:

2

i have developed a blogger-like archive feature (you know, from the feature module). i want to edit the .modulefile in order to automatically load the view-template (which is bundled in the feature) into the theme. is there a way to do it?

+1  A: 

On a general level: you should think "features = modules" and leaving theming for... themes! This does not mean that you shouldn't include a template with your feature, but that you should evaluate whether the template you have built suits a general use of your feature or it is specific for your currently used theme. If it is the latter case, you should not package your template file with the feature, but leave it with the theme instead. Just think to how the views module works, to get an idea of what I mean.

[Maybe you are already aware of this and made your considerations to this regards, in which case simply disregard what above. I thought about writing it because your sentence "I want the tpl.php to be actually available for the feature to use it (just as if it were in the active theme folder)" surprised me as general-use templates do not live in the theme folder but in the their module one, and moreover views already provide a "general use" template.]

That said, the way you normally tell drupal to use a given template, is via implementing hook_theme() in your module. In this case - though - given that you are going to override the template defined by views you should implement hook_theme_registry_alter() instead.

Somebody actually already did it. Here's the code snippet from the linked page:

function MYMODULE_theme_registry_alter(&$theme_registry) {
  $my_path = drupal_get_path('module', 'MYMODULE');
  $hooks = array('node');  // you can do this to any number of template theme hooks
  // insert our module
  foreach ($hooks as $h) {
    _MYMODULE_insert_after_first_element($theme_registry[$h]['theme paths'], $my_path);
  }
}

function _MYMODULE_insert_after_first_element(&$a, $element) {
  $first_element = array_shift($a);
  array_unshift($a, $first_element, $element);
}

Of course you will have to alter the theme registry for your view, rather than for a node (the original example refers to a CCK type).

As on using the template in the views_ui, I am not sure weather the features module already empty the theming cache when you install a feature (in which case you should be good to go). If not, you can trigger it manually by invoking cache_clear_all() from your install file. If emptying the entire cache is too much, you should dig into the views module on how to flush the cache relatively to a single views.

Hope this helps!

mac
features module does empty the theme cache, indeed.thanks a lot!
barraponto
+1  A: 

Try to add this to your feature .module file

/**
 * Implementation of hook_theme_registry_alter().
 */
function MYMODULE_theme_registry_alter(&$theme_registry) {
  $theme_registry['theme paths']['views'] = drupal_get_path('module', 'MYMODULE');
}

On the .install file use this

/**
 * Implementation of hook_enable().
 */
function MYMODULE_enable() {
  drupal_rebuild_theme_registry();
}
Lourenzo Ferreira