Skip to Content
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.
  • : Function ereg() is deprecated in /home/stevek/public_html/includes/file.inc on line 895.

Add Block Regions to your User Profile page in Drupal 5 and 6

Tags

Here's a small snippet to allow the output of blocks in your user profiles. This is assuming that you are currently over-riding the user page with the following code.
Update!I've added code for both Drupal 5 and 6, take a look.

Drupal 5


<?php
/**
* Catch the theme_user_profile function, and redirect through the template api
*/
function phptemplate_user_profile($user, $fields = array()) {
// Pass to phptemplate, including translating the parameters to an associative array. The element names are the names that the variables
// will be assigned within your template.
/* potential need for other code to extract field info */
return _phptemplate_callback('user_profile', array('user' => $user, 'fields' => $fields));
}
?>

(Code from: http://drupal.org/node/35728 )

and have your user_profile.tpl.php named as so.

Settings up your block regions:

First we'll slip into our theme's template.php file and make sure we create a new region.

<?php
function basic_regions() {
return array(
'sidebar_left' => t('left sidebar'),
'sidebar_right' => t('right sidebar'),
'content_top' => t('content top'),
'content_bottom' => t('content bottom'),
'header' => t('header'),
'footer_block' => t('footer'),
'profile_block' => t('profile blocks'),
);
}
?>

This allows us to create a new region called profile block which will hold all our blocks that we decide to put there. Now we want to be able to pass the $profile_block variable onto our user_profile.tpl.php to be outputted.

Adding the Block variables:


<?php
function _phptemplate_variables($hook, $vars = array()) {
switch ($hook) {
case 'user_profile':
$vars['profile_block'] = theme('blocks', 'profile_block');
break;
}
return $vars;
}
?>

Now we can go into our user_profile.tpl.php and add the following code anywhere in the file. This is where our newly created block region will be outputted.

<?php
echo $profile_block;
?>

Drupal 6

In your themename.info file (themename being replaced by your actual theme name) add your block region.

(In our themename.info)

<?php
regions[profile_block] = Profile Block
?>

We now create our user-profile.tpl.php file where we will output the block region and any other profile information that we need. To expose the $profile_block variable to our user-profile.tpl.php, we add the following code to our template.php file:

(In our template.php)

<?php
function phptemplate_preprocess_user_profile(&$variables) {
$variables['profile'] = array();
// Sort sections by weight
uasort($variables['account']->content, 'element_sort');
// Provide keyed variables so themers can print each section independantly.
foreach (element_children($variables['account']->content) as $key) {
$variables['profile'][$key] = drupal_render($variables['account']->content[$key]);
}
// Collect all profiles to make it easier to print all items at once.
$variables['user_profile'] = implode($variables['profile']);
$variables['profile_block'] = theme('blocks', 'profile_block');
}
?>

( Structure taken from: http://api.drupal.org/api/function/template_preprocess_user_profile/6 )
Note the added $variables['profile_block'] = theme('blocks', 'profile_block'); at the end. This allows us to access the block region, profile_block, by echoing out $profile_block in our user-profile.tpl.php file like so:

(In our user-profile.tpl.php)

<?php
echo $profile_block;
?>

Voila! Block regions in our user profile template file!