1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Output author's avatar in quote

Discussion in 'XenForo Questions and Support' started by CyberAP, Dec 4, 2011.

  1. CyberAP

    CyberAP Well-Known Member

    Is it possible to output author's avatar in quote by modifing template bb_code_tag_quote?
    I couldn't find there a variable of authors user ID.
     
  2. infis

    infis Well-Known Member

    You can find this by that way:
    1. See, where this template loading. I found it in library/XenForo/BbCode/Formatter/Base.php. And in file I found:
    PHP:
                    if ($this->_view)
                    {
                            
    $template $this->_view->createTemplateObject('bb_code_tag_quote', array(
                                    
    'content' => $content,
                                    
    'nameHtml' => $name,
                                    
    'source' => $source,
                                    
    'attributes' => $attributes,
                                    
    'ignored' => (isset($attributes['member']) && isset($this->_ignoredUsers[intval($attributes['member'])]))
                            ));
                            return 
    $template->render();
                    }
                    else
                    {
                            return 
    $this->_renderTagQuoteFallback($name$content);
                    }
    2. Now we can try to interpose into a template I will give the necessary variables:
    HTML:
    <div>{xen:helper dump, $attributes}</div>
    Result (for example) in quote area:
    Code:
    array
      'post' => string '109200' (length=6)
      'member' => string '823' (length=3)
    It is all :)
     
    CyberAP likes this.
  3. CyberAP

    CyberAP Well-Known Member

    This is really nice, but I wanted to do it without any addons. :)

    Actually there is an array $source but I don't know if there is user id within it.
     
  4. infis

    infis Well-Known Member

    Hm... But unless the variable {$attributes.member} is not that which you search?
    Code:
    [quote="CyberAP, post: 297468, member: 1756"]
    HTML:
    <div>{$attributes.member}</div>
    is output 1756 in template
     
    CyberAP likes this.
  5. CyberAP

    CyberAP Well-Known Member

    Yes! Thanks! That worked, but I get an error:

    Code:
    Template Errors: bb_code_tag_quote
    Argument 1 passed to XenForo_Template_Helper_Core::helperAvatarHtml() must be an array, string given in /library/XenForo/Template/Helper/Core.php, line 1534
    Argument 1 passed to XenForo_Template_Helper_Core::getUserHref() must be an array, string given, called in /library/XenForo/Template/Helper/Core.php on line 1562 and defined in /library/XenForo/Template/Helper/Core.php, line 1396
    Template Errors: bb_code_tag_quote
    Argument 1 passed to XenForo_Template_Helper_Core::helperAvatarHtml() must be an array, string given in /library/XenForo/Template/Helper/Core.php, line 1534
    Argument 1 passed to XenForo_Template_Helper_Core::getUserHref() must be an array, string given, called in /library/XenForo/Template/Helper/Core.php on line 1562 and defined in /library/XenForo/Template/Helper/Core.php, line 1396
    That avatar is displayed.
     
  6. infis

    infis Well-Known Member

    From template 'member_card'
    HTML:
                <img src="{xen:helper avatar, {$user}, l}" alt="" style="{xen:helper avatarCropCss, $user}" />
    
    where $user is must be array with two elements: $user.usr_id and $user.username.
    Don't know how it's make.
     
  7. CyberAP

    CyberAP Well-Known Member

    I don't understand why the user name is needed when it can be found using user id.
    So that means that <xen:avatar /> or {xen:helper avatar} can not be used here.
    Since we can't set arrays in templates it is not possible to complete my task. :(
    Thanks for the help!
     
  8. infis

    infis Well-Known Member

  9. Pepelac

    Pepelac Well-Known Member

    It's possible to create own array with <xen:set>

    xenset.png

    But avatar helper needs two more params - gravatar and avatar_date. And I cannot see an easy way to get them in bb_code_tag_quote template
     
    Fuhrmann, infis and CyberAP like this.
  10. CyberAP

    CyberAP Well-Known Member

    With the help of infis and Pepelac almost finished it. But it has no support of gravatar and always shows the first avatar you've set in your profile.

    PHP:
    <xen:set var="$avaUser.user_id">{xen:number $attributes.member}</xen:set>
    <
    xen:set var="$avaUser.username">{$nameHtml}</xen:set>
    <
    xen:set var="$avaUser.gravatar">0</xen:set>
    <
    xen:set var="$avaUser.avatar_date">1</xen:set>
     
    <
    xen:avatar user="$avaUsersize="s" />
     
    infis and Fuhrmann like this.
  11. infis

    infis Well-Known Member

    1. $attributes.member without xem:number is working
    2. $avaUser.gravatar not needed.

    :)
     
  12. CyberAP

    CyberAP Well-Known Member

Share This Page