XF 2.2 Conditional Template Extension?

kirsty

Member
I've got template_a with an extension in it

Code:
<xf:extension name='extension_name'>
   original stuff
</xf:extension>

and then I extend that in template_b

Code:
<xf:extends template='template_a'>
<xf:extension name='extension_name'>
  replacement stuff
</xf:extension>

which works fine.

But actually I only want to replace things conditionally. This will replace it only if the condition is met, but otherwise it'll be blank.
Code:
<xf:extends template='template_a'>
<xf:extension name='extension_name'>
  <xf:if is="$variable is not empty">
    replacement stuff
  </xf:if>
</xf:extension>

What I actually want is 'original stuff' to appear if the variable isn't set.

This version where I've put the condition outside doesn't do anything, I just get 'replacement stuff' whatever, which makes sense.
Code:
<xf:extends template='template_a'>
<xf:if is="$variable is not empty">
  <xf:extension name='extension_name'>
    replacement stuff
  </xf:extension>
</xf:if>

Is there a way I can get this to work? Perhaps some way to get the 'original stuff' value from 'template_a' in the extended template to put in an else clause? I don't want to put all the logic in 'template_a' as I want to extend it in several different ways and change the 'replacement stuff' in each of them.
 
Something like this perhaps
HTML:
    <xf:extension id="extention_id">
        <xf:if is="$true">
            <xf:comment>If true show this</xf:comment>
        <xf:else />
            <xf:comment>If false show the original content</xf:comment>
            <xf:extensionparent />
        </xf:if>
    </xf:extension>
 
Sorry, but if you could can you share light on what this extension tag is used for? Like under which use case...seems interesting to me.
 
Sorry, but if you could can you share light on what this extension tag is used for? Like under which use case...seems interesting to me.
Have a look at the forum_view and forum_view_type_article templates. The article one extends the forum_view one so it can do most of the same stuff but change some parts to show the information differently.

(Oh, I also found that the extensionparent bit is lurking there in the article template and I just hadn't noticed what it did! 🤦🏻‍♀️ )
 
Back
Top Bottom