I need to change layout of a profile depending on user's field. So, I need to either include regions in user-profile.tpl.php or access $user_profile to test that field in page.tpl.php.

I've seen this done, but can't find it now.

1 Answer 1


As for including regions in user-profile.tpl.php here how you do it.

In your custom theme add the following code to template.php file

function mytheme_preprocess_user_profile(&$variables) { 
  // List of all regions for the current theme
  foreach (system_region_list($GLOBALS['theme']) as $region_key => $region_name) {
    // Add content to $region variable
    if ($blocks = block_get_blocks_by_region($region_key)) {
      $variables['region'][$region_key] = $blocks;
    else {
      $variables['region'][$region_key] = array();

Then copy user-profile.tpl.php to your custom theme and then place the following code between any HTML tag.

print render($region['region_name']);
  • I need to re-check this, as this is what I have done, but all I've got was "Undefined variable $region" notice.
    – Mołot
    May 17, 2013 at 6:14
  • @Mołot do have else in your code?
    – Aboodred1
    May 17, 2013 at 14:36
  • 1
    actually, it worked after some more cache clears.
    – Mołot
    May 17, 2013 at 22:10

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.