5

This might be a stupid question... but I can't seem to figure it out.

I'd like to show the photo of an author beside their entry. I thought the proper variable was...

{{user.photoUrl}}

...until I logged out and my photo disappeared.

1 Answers1

12

That will get you the url of the current user's photo. To get an author's photo do this:

{{ author.photoUrl }}

If the author is not defined in your context but the entry is, then get the entry's author's photo as follows:

{{ entry.author.photoUrl }}

In Craft 4, the following should be used:

{{ entry.author.photo.url ?? '' }}
Ben Croker
  • 7,341
  • 26
  • 55
  • This method is now deprecated. Does anyone know the current method? The documentation says "Use getPhoto().getUrl() instead." but when I try entry.author.getPhoto().getUrl() I get an error. – Jim Pannell Nov 28 '22 at 12:57
  • 1
    If either the author or photo is not set, it will result in an error. I've updated my answer with a Craft 4 version that falls back to an empty string. – Ben Croker Nov 28 '22 at 14:00
  • Thanks @Ben Croker. Hope life is good! – Jim Pannell Nov 29 '22 at 11:25