0

I need to be able to display a particular user field in my node display.

The user field is a new, custom field I created, here: /admin/config/people/accounts and it's called 'organization role'. I was able to successfully add values for this field to my users. So the field itself works just fine in the user account settings. When you look at a user it shows their organization role. All that is fine.

However, in my node display I show the photo and name of the author of the node. These fields were made available to me when I installed display suite module and made a custom layout using that module, for my node page(s). However, no matter how many times I flush the cache my new user field 'organization role' is not available to me in my node's 'manage display' tab.

So my question is: how can I make that field available to my node display so I can display it with the rest of the node fields? (and once I make it available how do I actually display it?)

  • Below you said "this is a user-field in Account Settings...not a node-based field" but above you said "I went into the node display". Are you sure you are trying to manage the display of the users? (Configuration > People > Account settings > Manage Display ) and not of a node? – argiepiano Nov 10 '15 at 5:33
  • Actually, even if the layout is set to none, it should show up in Manage Display /admin/config/people/accounts/display check under disabled – No Sssweat Nov 10 '15 at 5:33
  • 1
    Yes it should... if @Sage is looking in the correct "Manage display" screen (for Users, not for nodes) – argiepiano Nov 10 '15 at 5:35
  • 1
    @argiepiano is correct. The field will only show up in manage display of user pages and NOT in manage display of Article (or any other content type) pages. – No Sssweat Nov 10 '15 at 5:40
  • Sorry for the confusion; my bad. The new field is available in the account settings just fine. However, I WANT the new field to be available for use in the node display. Is this possible and if so, how? – Sage Nov 10 '15 at 20:57
1

Display Suite only shows user fields Author and User Picture by default. However, there is a way to do this by defining a Code Field with Display Suite

Go to admin/structure/ds/fieldsand create a Code Field

Select Entities: Node (make this field available to nodes). You can do some additional filtering in Limit field if you want

Use the following code (be sure to select Display Suite code en Text format and use the php tags)

 $author = $entity->uid;
 $u = user_load($author);
 if (isset($u->field_special_field[LANGUAGE_NONE][0]['value'])) {
   return $u->field_special_field[LANGUAGE_NONE][0]['value'];
 }

(Replace field_special_field with the name of your field,e.g. field_organization_role). Then go to your Content type Manage display and add the new field.

Another way:

This is really easy to do with Views, though. Create a View of your content type, select Unformatted list of fields. Add all the fields you want from your Content Type. Go to Advanced and create a Relationship to Content: Author. This will expose ALL the User fields in the list of Fields. You can add them at your heart's content. If you want to show only one node (rather than a list of all nodes) you can use Content: Nid in the Contextual filter area and pass the nid at the end of the url, as in www.example.com/view_name/[nid]

  • Alright, I've edited and tested it. It works fine, and shows the field for the author of the node. – argiepiano Nov 12 '15 at 3:58
  • You're the man! Thank you. The only minor issue I encountered was that I had no display suite code text format (at first) and it would just output the straight code obviously. But naturally you have to turn on that text format module that comes with the display suite module. Worked like a charm. – Sage Nov 14 '15 at 1:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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