Handling single-line profile fields
Last modified: August 27, 2009 - 00:28
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 single-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_cityused in the example below. (Tip: go to administer -->> settings -->> profile and in the second column it will give you the field name.) - Tested and works with Drupal 4.5 and 4.6
- Change the div class names or the prefix text to suit.
<?php if($account->profile_city): ?>
<div class="fields">City: <?php print check_plain($account->profile_city) ?></div>
<?php endif ?>
Shouldn't it
Shouldn't it be:
<?php if($user->profile_city): ?><div class="fields">City: <?php print check_plain($user->profile_city) ?></div>
<?php endif ?>
Or is the data sanitization performed elsewhere?
Hello, can anybody say me
Hello,
can anybody say me how this works with cck and drupal6 ? Thanks for any help.
best regards.
Change in Drupal 6
Hello Ariadoss,
In order to show custom fields added throgh Profile module, you have to replace $user variable with $account variable.
For example
<?php if($account->profile_city): ?><div class="fields">City: <?php print check_plain($account->profile_city) ?></div>
<?php endif ?>
changes to
<?php if($account->profile_city): ?><div class="fields">City: <?php print check_plain($account->profile_city) ?></div>
<?php endif ?>
Hmm not working for my 5.X
Hmm not working for my 5.X Site. I was trying to get a print_r of all the available fields and then hand pick what I wanted. How can we get a dump of all elements that can be displayed (Drupal 5)?
What about Content profile?
I can't extract the field from the content profile module, which I use instead the core one.