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_city used 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 ?>

Comments

Ariadoss’s picture

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?

IckZ’s picture

Hello,
can anybody say me how this works with cck and drupal6 ? Thanks for any help.

best regards.

khan2ims’s picture

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 ?>

Imran Khan
Project Manager
New Earth Marketing

goose2000’s picture

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)?

Noira’s picture

I can't extract the field from the content profile module, which I use instead the core one.