XF 2.2 Avatar template syntax?

grantus

Active member
What would be the proper avatar code to display in a template within my loop?

I've tried <xf:avatar user="{$value.user_id}" size="s" defaultname="{$value.username}" /> within my own foreach loop, yet it doesn't return a user_id.

I've also tried

Code:
<img src="{{ link('data/avatars/m/') }}{{ number(floor({$value.user_id})/1000) }}/{$value.user_id}.jpg" alt="{$value.username}" />

and it works, however the issue is the number(floor part. It seems to round up over 5.

For example, I have a user_id of 18551 so it spits out 19 instead of 18. Another user_id is 5131 and it shows 5 as it should.
 
You fetch the avatar by passing the object to the user parameter, not the user_id.

<xf:avatar user="{$value}" size="s" /> should do the trick.
 
You fetch the avatar by passing the object to the user parameter, not the user_id.

<xf:avatar user="{$value}" size="s" /> should do the trick.
My query is not a finder though, I'm using a regular sql query and in those results I have the user_id, so I was looking for a way to use that instead.
 
The number() template function is for formatting numbers for display according to the language configuration, so you wouldn't want to use it here. Though for various reasons you might want to just fetch the corresponding user entities and pass them to the template instead.
 
The number() template function is for formatting numbers for display according to the language configuration, so you wouldn't want to use it here. Though for various reasons you might want to just fetch the corresponding user entities and pass them to the template instead.
I think that's what I'll end up doing, just setting it up first and then passing it through.
 
Top Bottom