4

I'm using the Chaos tools display suite module to create a 'mini_teaser' view mode for my user profiles, but I can't seem to get drupal to read a custom template 'user-profile__mini_teaser.tpl.php' in my theme folder. In my user preprocess function, I'm adding theme suggestions, but they don't seem to work. Any ideas?

1

It's hard to tell without seeing your code but off the top of my head your preprocess function should look something like this:

function MYTHEME_preprocess_user_profile(&$vars) {
  if ($vars['view_mode'] == 'mini_teaser') {
    $vars['theme_hook_suggestions'][] = 'user_profile__mini_teaser';
  }
}

Or a more generic solution:

function MYTHEME_preprocess_user_profile(&$vars) {
  $vars['theme_hook_suggestions'][] = 'user_profile__' . $vars['view_mode'];
}
| improve this answer | |
  • Just tried this, but the $vars['view_mode'] value appears to be located in $vars['elements']['#view_mode']. Found by dpm($vars); in the preprocess function. – Neograph734 Mar 13 '15 at 13:43
0

Normally you would replace the underscores from

$variables['theme_hook_suggestions'][] = 'user_profile__mini_teaser'; 

with hyphens in the template file name:

i.e, rename template file to:

user-profile--mini-teaser.tpl.php

After clearing theme registry cache, see if that, or a similar underscore / hyphen filename adjustment helps.

| improve this answer | |

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.