Friday, June 24, 2011

Customizing the user profile layout

Step 1 - is to override the default User Profile page layout by uploading a custom user-profile.tpl.php* file to your active theme folder.

Drupal will automatically detect the presence of your custom user-profile.tpl.php and override the default user profile layout. To make this happen, you need to rebuild the theme registry, which you can do by clearing the caches (for example using the button on the admin/settings/performance page), or simply by visiting the admin/build/modules page.

* note that in Drupal 6.x, your custom user profile layout file name uses a hyphen, instead of an underscore.

Step 2 - is to customize your user-profile.tpl.php layout file.

By default, all user profile data is printed out with the $user_profile variable. If there is a need to break it up you can use $profile instead.

As an example, the following snippet inserted in your custom user-profile.tpl.php will display the default user profile layout.



Available variables:

$user_profile: All user profile data. Ready for print.
$profile: Keyed array of profile categories and their items or other data provided by modules.

To check for all available data within $profile, insert the following snippet at the bottom of your custom user-profile.tpl.php.




Available variables

The following is a list of variables that is available to your custom user-profile.tpl.php.

print '
'. check_plain(print_r($profile, 1)) .'
';

Step 3 - Load profile variables

If you want to load the profile variables (profile module) you can use this code in user-profile.tpl.php


profile_load_profile($account);
// now you can call the profile field like profile_firstname
echo $account->profile_firstname;

No comments:

Post a Comment