Skip to content

Instantly share code, notes, and snippets.

@justin-endler
Last active October 13, 2015 17:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justin-endler/4233861 to your computer and use it in GitHub Desktop.
Save justin-endler/4233861 to your computer and use it in GitHub Desktop.
Register custom view templates from a module in Drupal 7.
<?php
/**
* Implements hook_theme().
*
* Drupal 7 view template-ing from a module.
*
* @author Justin Endler
*/
function mymodule_theme($existing, $type, $theme, $path) {
$module_path = drupal_get_path('module', 'mymodule');
// Add to theme registry.
// @todo the custom preprocess registration is ignored
$themes['views_view_fields__myview'] = array(
'template' => 'views-view-fields--myview',
'path' => $module_path . '/theme',
'base hook' => 'views_view_fields',
'type' => 'module',
'theme_path' => $module_path,
'preprocess functions' => array(
'template_preprocess',
'template_preprocess_views_view_fields',
'mymodule_preprocess_views_view_fields__myview',
),
);
return $themes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment