1

I want to print a custom user field of the commenters. It is an Link field (https://www.drupal.org/project/link). Some users have that field completed and other not.

I've read a lot of posts related to this and tried several solutions. The only code that seems to nearly work OK is the following (found in https://drupal.stackexchange.com/a/129222):

<?php print render(field_view_field('user',user_load($comment->uid), 'YOUR-CUSTOM-USER-FIELD'));?>

The field shows, but there are 2 problems:

1) It causes 2 errors of "Strict warning: Only variables should be passed by reference en include() (line 73 of .../templates/comment.tpl.php)."

2) It shows the entire field, including its label and the complete link with the settings of the field. I only want the "raw" value of the field, the text that users introduce in the field.

Thanks for your help!

1 Answer 1

0

You can use the field_get_items() to get all values for this field, after use field_view_value(). Example below:

// user_uid_optional_load() will load the user object with all custom fields

$account = user_uid_optional_load($comment->uid);

$items = field_get_items('user', $account, 'field_name');

// as a example I'm using the number 0 as delta $value = render(field_view_value('user', $account, 'field_name', $items[0]));

1
  • I've tried adding your code to comment.tpl.php (as provided, just changing field_name to the appropiate name and adding the php tags) and it doesn't work. It doesn't show the field and it shows 2 errors of "Strict warning: Only variables should be passed by reference en include()...". The line of code included in my question also gave the errors but at least was showing the field. Maybe I'm missing something (I'm not a developer, I need the exact code and/or instructions for dummies).
    – migueltic
    Commented Feb 3, 2015 at 23:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.