Handling URL profile fields
Task · theme URL profile fields · theme user profiles · Themers · Drupal 4.5.x or older · Drupal 4.6.x · Drupal 4.7.x · Drupal 5.x
Last modified: August 27, 2009 - 00:26
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 custom User Profile URL fields. If the user has not specified any link, 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 URL field name. In the example that is currently
$urlfieldname='profile_weburl'(Tip: go to administer -->> settings -->> profile and in the second column it will give you the name of the URL field.) - If you are using this snippet more than once in the same user_profile.tpl.php file add a number to the end of the $urlfieldname each time you copy the snippet. e.g. $fieldname1, $fieldname2, $fieldname3 etc.
- Change the div class names or the link prefix text to suit.
<?php $urlfieldname='profile_weburl' ;?>
<div class="fields">
<?php if($account->$urlfieldname): ?>
Website URL: <a href="<?php print check_url($account->$urlfieldname) ?>"><?php print check_url($account->$urlfieldname) ?></a>
<?php endif; ?>
</div>NOTE to HANDBOOK EDITORS: If you are editing handbook pages, please test the snippet as well.

Error in D6
I put this code into my user-profile.tpl.php page and Drupal 6 came back with this error:
Googling this led me to this page where I learned that the second $ in the if statement (lines 3,4,5) is the culprit.
So, here's a fixed version, fit for Drupal 6.
<?php $urlfieldname='profile_weburl' ;?><div class="fields">
<?php if($account->urlfieldname): ?>
Website URL: <a href="<?php print check_url($account->urlfieldname) ?>"><?php print check_url($account->urlfieldname) ?></a>
<?php endif; ?>
</div>
good catch
Normally I test the snippets before finalising a handbook page. not sure how that bug slipped through. I've ammended the snippet with the correct syntax and left a note for editors to test in future when editing (the snippet has changed a few times since the original was submitted).
cheers
dub
Er, not really.
It was correct as it was (in fact that syntax was used in your original snippet too, and was correct then as well).
The only way I can reproduce the error is by removing the first line of the snippet, which sets $urlfieldname to the name of the profile field you created. arilikeairy, are you sure you included this line and that you entered it correctly (the variable must be exactly
$urlfieldnameand the 'profile_weburl' string is what you change to match your profile field)?The snippet with the $'s removed only works if your profile field is named 'urlfieldname', in which case the first line of the snippet is pointless. If you think it makes more sense like that, by all means change it but please also remove that first line and update the description to reflect the changed usage.
my mistake
you're right John. My mistake. will ammend the snippet to suit