0

I added for users a couple of fields : field_telephonenumber and field_company

how can i display them in user.html.twig or maybe page.html.twig

3

You can configure which fields are displayed in the view mode compact:

admin/config/people/accounts/display/compact

Then you can in twig display all fields with

{{ content }}

or single fields with

{{ content.field_example }}

To put a user in a page template you can use Twig Tweak:

{{ drupal_entity('user', 1, 'compact')

The third parameter is the view mode and you can use theme hook suggestions to catch this with your custom user twig to make adjustments of the user fields.

  • 1
    What part of it did not work? And don't change the question, so that the answer doesn't fit anymore. – 4k4 Oct 27 '16 at 9:58
  • I changed the page because i made a mistake but i tested your answer on both pages the {{ content.field_example }} didn't work – usethe23 Oct 27 '16 at 12:14
  • 1
    Your first question was about the user twig. This is, where you normally display user fields. If you now ask, how to display user fields in other twigs, like a page twig, this is too broad for an answer. You need to be more specific. – 4k4 Oct 27 '16 at 12:58
  • I tried to display it in a user.html.twig page but it didn't work so i wanted to try maybe with something else and still it didn't work. I'm sorry i should've edited my question to say on any page possible, thank you for your help – usethe23 Oct 27 '16 at 13:17
  • 1
    For user twig the key is to add the new fields to the view mode. For page I put one possible solution in the answer. – 4k4 Oct 27 '16 at 13:28

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.