XF 2.2 PHP Callback for support older versions and new XF tags

AndrewSimm

Well-known member
I am working on making one of my add-ons work with an older version of XF. One of my challenges is my add-on uses <xf:profilebanner in one of its templates that that tag does not work with XF 2.1.

First I tried using conditional statements but that doesn't work as the install fails. Next I tried a callback in the template modification and while they let me install it now renders the "<xf:profilebanner " tag in the code versus the results of that tag.

Any thoughts?
 
We recommend against trying to support multiple versions in a single release, as ensuring backwards and forwards compatibility is entirely up to you. However, <xf:profilebanner> ultimately just calls the profile_banner template function, so you can likely do that conditionally:

HTML:
<xf:if is="$xf.versionId > 2020000">
    {{ profile_banner($xf.visitor, 'm')) }}
</xf:if>
 
We recommend against trying to support multiple versions in a single release, as ensuring backwards and forwards compatibility is entirely up to you. However, <xf:profilebanner> ultimately just calls the profile_banner template function, so you can likely do that conditionally:

HTML:
<xf:if is="$xf.versionId > 2020000">
    {{ profile_banner($xf.visitor, 'm')) }}
</xf:if>
<xf:profilebanner> has an opening and closing tag. If I use {{ profile_banner($user 'm') }} I get a DIV that doesn't show because nothing is in it.

<div class="memberProfileBanner memberProfileBanner-u1-m" data-toggle-class="" style="background-image: url(/data/profile_banners/m/0/1.jpg?1718165416); background-position-y: 50%;"></div>
 
See \XF\Templater\Templater::fnProfileBanner. the children are passed as an argument:

HTML:
<xf:if is="$xf.versionId > 2020000">
    <xf:set var="$children">
        <div class="some-class">
            <p>Some child.</p>
        </div>
    </xf:set>

    {{ profile_banner($xf.visitor, 'm', false, [], $children) }}
</xf:if>
 
See \XF\Templater\Templater::fnProfileBanner. the children are passed as an argument:

HTML:
<xf:if is="$xf.versionId > 2020000">
    <xf:set var="$children">
        <div class="some-class">
            <p>Some child.</p>
        </div>
    </xf:set>

    {{ profile_banner($xf.visitor, 'm', false, [], $children) }}
</xf:if>
Ahh, I see! It makes a lot of sense when ou look at the function.
public function fnProfileBanner($templater, &$escape, $user, $sizeCode, $canonical = false, $attributes = [], $contentHtml = '')
 
Yes, most non-syntax-related tags really just compile into templater method calls. The first two arguments are implicit.
 
Back
Top Bottom