theme user profiles
Profile edit form on same page as account information
Sometimes, you need to merge user account edit screen and profile values to one form. Here is a snippet how to do it.
Example:
You want to merge User edit form with My personal data section of the profile.
First, you need to create your own module. Implement hook_user():
/*
* Implementation of hook_user().
*/
function mymodule_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'form':
// We are at edit screen. Load form data for "My personal data" category.
return profile_form_profile($edit, $user, 'My personal data');
break;
}
}Code above will merge these two forms together and display profile form on user edit screen.
Insert Subscribed Organic Groups List
You can add a list of groups that the user has subscribed to with the following snippet. Keep in mind that if you use this snippet outside of the user profile template as set up on the Customising the user profile layout page you may need to add global $user; at the beginning to make sure you have the full user object to work with.
<h2>Groups</h2>
<div class="item-list"><ul>
<?php
$groups = $user->og_groups;
if($groups){
foreach($groups as $group){
echo "<li>";
print l($group[title], 'node/'.$group[nid]);
echo "</li>";
}
}
else {
echo "<li>$user->name has joined no groups</li>";
}
?>
</ul>Howto: Make the user profile layout compact (with css only)
Screen Shots:
Before: http://img205.imageshack.us/img205/899/beforedw4.png
After: http://img164.imageshack.us/img164/2630/aftergv7.png
To make the view of the 'user profile' page compact, add the following CSS to the end of your theme's .css file. This is generally better than modifying the profile.css or user.css (or drupal.css in 4.7) directly.
.profile h2.title {
margin-top:13px;
border-bottom-width: 1px;
border-bottom-style: solid;
}
.profile dd {
min-height:10px;
margin:5px;
margin-top:13px;
margin-left:180px;
margin-bottom:0px;
padding:0px;
width:300px;
height:auto;
position: relative;
border-bottom: 1px dotted #d9d9ff;
}
.profile dt {
width:180px;
background-color: #DEE;
border-bottom: 1px solid white;
float:none;
margin-bottom: -30px;
}Alternate version using a floating dt
.profile h2.title {
margin-top: 15px;
border-bottom: 1px solid #777777;
}
.profile dt {
margin: 0;
padding: 2px 3px;
width: 120px;
background-color: #dee;
border-bottom: 1px solid white;
float:left;
}
.profile dd {
margin: 0 0 0 130px;
padding: 2px 3px;
border-bottom: 1px dotted #d9d9ff;
}Note that if the changes aren't showing up it is probably because of caching so clear your browser's cache (F5 works on many browsers.)
Handling date profile fields
Adding dates to your custom profile.
This has only been tested with 4.7.0 and 5.3
This module adds a birthday into the custom profile, but you can easily customize it to add any date, such as date of death for a obituary (for a famous actor's profile maybe). You must have made a template.php already. This code should be added to your user_profile.tlp.php file.
<div class="fields"><b>Birthday:</b> <?php print $user->profile_birthday['month']."/".$user->profile_birthday['day']."/".$user->profile_birthday['year'];?>Note that you will have to customize the profile_birthday to whatever your settings are in admin/settings/profile. To change the date layout, just move the month, day, and year around, like so:
<div class="fields"><b>Birthday:</b> <?php print $user->profile_birthday['year']."/".$user->profile_birthday['month']."/".$user->profile_birthday['day'];?>Convert date array to date variable
Here's a simple function that will convert the profile date array to a date variable. Maybe a little clunky but you get the point:
<?php
function convert_profile_date($profile_date_ar) {
// takes a profile date array and converts it to a date variable.
$output = mktime(0, 0, 0, $profile_date_ar['month'], $profile_date_ar['day'], $profile_date_ar['year']);
return $output;
}
?>Handling checkbox profile fields
PLEASE NOTE! These snippets are user submitted. It is impossible to check them all, so please use at your own risk! For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.
Description
This php snippet illustrates how to use custom User Profile checkbox Fields.
Dependencies: profile.module
Usage
- For use in your user profile page override
- Using a text editor like NOTEPAD.EXE or an equivalent, copy and paste the code into your user_profile.tpl.php file
- In the example snippet we used a custom checkbox for "Click if you're a MAC user" and called the form name
profile_mac - Tested and works with Drupal 4.5 and 4.6
- Change the div class names or the prefix text to suit.
<div class="fields">
<?php if ($account->profile_mac == '1') {print "I use a mac" ;}; ?>
<?php if ($account->profile_mac == '0') {print "I do not use a mac" ;}; ?>
</div>Handling multi-line profile fields
PLEASE NOTE! These snippets are user submitted. It is impossible to check them all, so please use at your own risk! For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.
Description
This php snippet displays multi-line textfields. If the user has not specified anything, it displays nothing
Dependencies: profile.module
Usage
- Using a text editor like NOTEPAD.EXE or an equivalent, copy and paste the code into your user_profile.tpl.php file
- Change the custom profile field name from
profile_biographyused in the example below. (Tip: In Drupal 4.x go to administer -->> settings -->> profile and in the second column it will give you the field name. In Drupal 5.x the profiles settings page can be found at administer -->> user management -->> profiles) - Tested and works with Drupal 4.5, 4.6, 4.7.x and 5.x
- Make sure you us the snippet variation of the snippet that matches the version of Drupal you are using.
- Change the div class names or the prefix text to suit.
works with Drupal 4.5.x and Drupal 4.6.x
<?php
if($account->profile_biography):
?>
