2

Is there a way to theme a user's profile but make it per user instead of globally on all users?

  • are you using the profile2 module or the deprecated user-profile module? – karth Oct 28 '11 at 9:19
  • Its the one that comes with Drupal 7. – Mythrillic Oct 28 '11 at 11:40
3

You can use the Drupal theme suggestions to specify templates based on any of the users fields.

I've implemented a theme for each of the different roles on my site for instance:

function [theme]_preprocess_user_profile(&$vars) {

foreach($vars['elements']['#account']->roles as $role):

    $vars['theme_hook_suggestions'][] = 'user_profile__'. str_replace(' ','-', $role);

endforeach;

}

To do the same with a users name for instance you could do:

$vars['theme_hook_suggestions'][] = 'user_profile__'. str_replace(' ','-', $vars['elements']['#account']->name);

Then make sure you've got the corresponding theme files inside your theme folder. All underscores are converted by Drupal to dashes so a suggestion of user_profile__dave would become user-profile--dave.tpl.php for instance.

| 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.