Customising the user list layout

description

This describes how to override the default user list page layout when using phptemplate based themes and the profile.module.

The user list page is displayed when you click on www.example.com/profile. For an example, click through to the Drupal.org user list page.

Using this override you can control precisely which profile fields are displayed and their positioning/layout.

Note this snippet will work with sites using Drupal 4.5 or Drupal 4.6. Scroll down or click for an updated version for Drupal 4.7

Step 1 of 2

In a text editor like notepad.exe, create a file called template.php using the the following snippet. If you already have a template.php file, simply add it to your existing one.

<?php

/**
* This snippet works with Drupal 4.5 and Drupal 4.6
* and will NOT work with Drupal 4.7
*/

function phptemplate_profile_profile($user, $fields = array()) {
/**
* This snippet catches the default user list pages layout
* and looks for a profile_profile.tpl.php file in the same folder
* which has the new layout.
*/
return _phptemplate_callback('profile_profile', array('user' => $user, 'fields' => $fields));
  }
?>

Upload your template.php file to your active theme folder.

Step 2 of 2

The template.php snippet catches the default user list page layout before it's displayed and looks in the same folder for a profile_profile.tpl.php file which determines the new layout.

A very simple/shortened example of a profile_profile.tpl.php file maybe illustrated as follows....(e.g. I have setup custom extended user profile fields called profile_city, profile_country, profile_postcode)....

<?php if($user->picture): ?>
<div class="picture">
<img src="/<?php print $user->picture ?>">
</div>
<?php endif; ?>
<div class="custom_profiles">
<div class="fields">Name: <?php print $user->name ?></div>
<div class="fields">City: <?php print $user->profile_city ?></div>
<div class="fields">Country: <?php print $user->profile_country ?></div>
<div class="fields">Postcode: <?php print $user->profile_postcode ?></div>
</div>

Upload your profile_profile.tpl.php file to your active theme folder and go to your user list page at www.example.com/profile to see the new layout.

Notes

  • Name the classes or change the layout to whatever you want.
  • Edit your style.css file or whatever your main stylesheet is called to control the the class styles.
  • You can include the user profile page snippets if you like
  • Please post tips/tricks discuss this handbook page at this thread.
 
 

Drupal is a registered trademark of Dries Buytaert.