I tried this http://www.fredparke.com/blog/using-custom-template-files-different-display-modes-drupal-7, but doesn't work, gives errors and tried this How to provide template for particular view mode? kind of works, but gives errors.

My content type is product_display and view mode is Product List, created with display suite. I need this, so I could delete h2 title from it, because views forces title output via rendered entity format no matter what.

Errors I get are either Notice: Undefined index: product_display in mytheme_preprocess_node() (line 170 of /template.php).

or this https://i.sstatic.net/s6bEn.jpg

  • What errors are you getting? It could be the errors say something about what it is wrong with what you are doing.
    – apaderno
    Commented Mar 25, 2014 at 22:48
  • What errors? Are you using the machine name of the content type and view mode? I use that method just about every single day.
    – mpdonadio
    Commented Mar 25, 2014 at 22:48
  • I updated the question with errors. Commented Mar 26, 2014 at 7:44

1 Answer 1


You need theme_hook_suggestions.

     * Implements hook_preprocess_node().
    function MYMODULE_preprocess_node(&$vars) {

      if ($vars['type'] != 'product_display'){

      if($vars['view_mode'] == 'product_list'){

        $vars['theme_hook_suggestions'][] =  'node__' . $vars['type'] . '__' . $vars['view_mode'];


Now you will be able to use: node--product_display--product_list.tpl.php

Make sure you have to change MYMODULE.

If you want to use it from template php then use following code. I also assume you use zen theme:

function template_preprocess_node(&$variables) {
 if ($variables['type'] == 'product_display' && $variables['view_mode'] == 'product_list'){
// looks for node--node_type--view_mode.tpl.php in your theme directory
   $variables['theme_hook_suggestions'][] =  'node__' . $variables['type'] . '__' . $variables['view_mode'];
  • you sure underscores are allowed? I used dashes. i'll let you know later if worked. Commented Mar 26, 2014 at 6:52
  • Yeah, I get errors, listed above. Commented Mar 26, 2014 at 7:45
  • @StephenR Is there any reason you've provided 5 separate answers to this question? Please add all the information to a single answer, unless the approach for each is completely different (which it isn't in this case). I've deleted the other ones and merged what's relevant into this one. You should still be able to see the deleted answers if there's anything else you want to copy-paste from them into this one.
    – Clive
    Commented Mar 26, 2014 at 11:34
  • @OptimusPrime the error "undefined index" means you are trying to access an array element that doesn't exist. So if you get an "undefined index of product_display" it means that you are trying to do something like $foo['product_display'] somewhere (on/near line 170?) in your code. So in your actual code, could you be using this as an index/key into $variables instead of accessing it as the value of $variables['type']?
    – Jimajamma
    Commented Mar 26, 2014 at 12:51
  • 1
    thanks @Clive for correcting me. I am pretty new to the stack-overflow and i am still struggle to post my answers properly.
    – Stephen.R
    Commented Mar 26, 2014 at 22:00

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.