How do I print the author details for a node? In particular, I am interested to the following values.

  • Author picture
  • Name
  • Description

In Drupal 7, I would use this code.

<?php print $author_data['picture'];?>
<?php print $author_data['name']; ?>
<?php print $author_data['description']?>

What is the equivalent in Drupal 8?


You can see the available variables at the top of the twig file, two are already there:

  • author_picture: The node author user entity, rendered using the "compact"
  • author_name: Themed author name field.

For other fields of the author you can print the field value:

{{ node.Owner.name.value }}

And description, if you have added this field to user:

{{ node.Owner.description.value }}
  • Thank you. Now I understent. And to added field to user I need to write simple module or there is easier way?
    – SakaSerbia
    Apr 1 '16 at 10:21
  • I found /admin/config/people/accounts/fields.. :)
    – SakaSerbia
    Apr 1 '16 at 10:26
  • As an alternative, Drupal core also automatically provides the compact view mode, author_picture is actually that. See api.drupal.org/api/drupal/core%21modules%21node%21node.module/…. That means you can control which fields are shown there and can also provide a custom template for that, then you can re-use that in many different node templates and don't have to duplicate all the markup.
    – Berdir
    Apr 2 '16 at 18:22

This is what worked for me in the node template for any custom field:

{{ node.uid.entity.field_name.value }}

I'm using Drupal 8.3.7

EDIT: This is what I'm doing for the profile picture. I'm creating a rendering object so I can specify a theme and an image style:

            {% set imagestyle = {
              '#theme':      'image_style',
              '#style_name': 'user_avatar_80x80',
              '#uri':        node.uid.entity.user_picture.entity.uri.value,
              '#attributes': { class: 'authorImg' },
            } %}
            <div class="authorCol1">{{ imagestyle }}</div>
  • What does it mean to be un Drupal 8.3.7?
    – UltraBob
    Sep 14 '17 at 9:02
  • 1
    8.3.7 is the version of Drupal that he is using. Specifying the particular version is helpful as things sometimes change between versions.
    – diamondsea
    Mar 16 '18 at 14:00

You can use <span>{{ 'Author: '|t ~ author_name|striptags }}</span> in Drupal 8.

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.