0

I am loading a user via user_load_by_name() in my themename.theme. Now I would like to view some of the fields in my template. But how to get/render the fields?

I can use user_view() to render the whole user. But I would like to access only some fields and make them available in the template.

  • 1
    Does drupal.stackexchange.com/questions/144947/… give you enough to go on? – Clive Oct 1 '15 at 10:39
  • @Clive awesome, thanks a lot. toArray() works. But seems like then we loose information about the fields because when I iterate through them in the template and print them like {{ field }} Its not treated like a field. So is there a way of transforming them into field objects? – Finn Oct 1 '15 at 10:59
  • 1
    It think that's something like $user->field_name->view($display_mode) @Finn (like drupal.org/node/2208327) – Clive Oct 1 '15 at 11:03
  • @Clive that totally solved my issue. Thanks so much! – Finn Oct 1 '15 at 12:01

Your Answer

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

Browse other questions tagged or ask your own question.