I'm getting default avatars instead of user uploaded

(probus) #1

I have a plugin using a custom template for the topic list. I’m trying to get the latest poster avatar. Using:

renderAvatar(this, {usernamePath: 'topic.last_poster_username', imageSize: 'medium'})

renders the correct users’ avatar, but it always comes up as the default (letter) avatar and not the user uploaded avatar (in case the user has uploaded one).

How do I get it to render the user uploaded avatar?

(probus) #2

Can I provide some other information? @eviltrout you seem to be the author of that particular helper, what am I doing wrong?

(Kane York) #3

I think you need the avatar_template member of the user json.

(probus) #4

What do you mean exactly?

(Robin Ward) #5

There is an avatar_template attribute returned by things that display avatars. It contains the information to render the correct avatar. You need to pass it through.

(probus) #6

I guess I don’t understand how to do that. I’m trying to create a custom column for the topic list template with the latest poster avatar in it.

Here’s my simple component to display an avatar (latest-avatar.js.es6):

import { renderAvatar } from 'discourse/helpers/user-avatar';
export default Ember.Component.extend({
  render: function(buffer) {
     var avatar = renderAvatar(this, {usernamePath: 'topic.last_poster_username', imageSize: 'medium'});

And the line in the template to call it:

{{latest-avatar topic=model}}

How do I pass the avatar_template and where to? What do I need to change in this simple example?

(Robin Ward) #7

If you just want to display an avatar, you should be able to just use the {{avatar}} helper in your template:

{{avatar user imageSize="small"}}

However there is no simple path in our object graph to the last poster object. It’s in the posters array of the topic list. You will have to create a computed property to get the last poster from that array by filtering where extras === latest.