1

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

custom_entity__custom_entity__view_mode_name

Now I want to put

custom-entity--custom-entity--view-mode-name.tpl.php

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.

0

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 '14 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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