XF 2.0 Extending <xf:avatar.../> template tag functionality

CMTV

Well-known member
Hi!

I extended user entity structure and added custom column is_pixelated to it.

Now I am trying to make every avatar of those users that have true in is_pixelated column to have image-rendering: pixelated CSS property in avatar img tag.

xenForo uses <xf:avatar.../> template tag to display avatars. I guess I need to somehow extend it in order to take into consideration my custom column when displaing avatar...
 
Yeah you would likely need to extend the Templater class using the "Class extensions" system.

Once you do that, you'd be able to extend the fnAvatar method.

You could add an additional class to be applied by modifying the attributes array and adding an additional class to the innerclass attribute. This will then get applied to the img element, then you'd just add some styling via CSS/Less to style that appropriately.
 
Yeah you would likely need to extend the Templater class using the "Class extensions" system.

Once you do that, you'd be able to extend the fnAvatar method.
Chris D, thank you it really works!

I have extended Templater class and fnAvatar method:
PHP:
public function fnAvatar($templater, &$escape, $user, $size, $canonical = false, $attributes = [])
    {
        $html = parent::fnAvatar($templater, $escape, $user, $size, $canonical, $attributes);

        /* Adding pixelated image-rendering CSS property to user avatars */
        if($user->minecraftskins_is_using_minecraft_skin)
        {
            $html = str_replace('class="', 'class="minecraft-avatar ', $html);
        }

        return $html;
    }
 
Top Bottom