I see in theme suggestion array that I can override template for my custom entity type based on view mode like this:


Now I want to put


inside custom module.

I'm trying something like:

function custom_module_theme_registry_alter(&$theme_registry) {

  if (isset($theme_registry['entity'])) {

    $entity = &$theme_registry['entity'];

    if (!isset($entity['theme paths'])) {
      $entity['theme paths'] = array();

    $entity['theme paths'][] = drupal_get_path('module', 'custom_module') . '/templates';

    if (isset($entity['theme path'])) {
      $entity['theme paths'][] = $entity['theme path'];
      unset($entity['theme path']);

So my template file is in custom_module/templates directory.

But after clearing cache always entity.tpl.php is used for all view modes.

1 Answer 1


I did this using hook_process_HOOK($variables) for nodes view mode tpls :

function view_mode_tpl_preprocess_node(&$vars) {
  $vars['theme_hook_suggestions'][] = 'node__' . $vars['node']->type . '__' .$vars['view_mode'];

hope this will help you.

  • Thx, but Drupal provides template suggestion by view mode by default. I am asking about loading custom template from a module.
    – Codium
    May 26, 2014 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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