1

I have a blog where basic author information needs to be printed out.

Basically, I want to print author name and profile picture in my article teaser template.

I tried googling but none of the answers seemed to help.

Can I somehow access Author object?

1 Answer 1

4

Put this on top of your node.html.twig or similar template

{% 
  set author_pic = {
    '#theme':      'image_style',
    '#style_name': 'thumbnail',
    '#uri':        node.uid.entity.user_picture.entity.uri.value,
    '#attributes': { class: 'authorImg' },
  } 
%}

Use this anywhere in the same template you want to output the author image

{{ author_pic }}
2
  • Thanks, works fine. Though, I had to delete /* image style name */ comment, otherwise php error occurs. Mar 5, 2018 at 11:23
  • Yes you are right I did not realize ... corrected it
    – GiorgosK
    Mar 5, 2018 at 13:18

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.