XF 2.2 Is there a way to only enable a template modification based on an expression?

RobinHood

Well-known member
I keep getting Template tags are not well formed and other template errors when trying to add conditional logic to my template edits so that I can turn them on an off based on an ACP check box option.

Is there a way to only 'activate' certain template modifications based on expressions at a higher level? Sort of like how navigation options have display conditions?

Or do I need to somehow rejig all my regexs so that I don't get template errors with I add these conditions? They work fine without them.

Or is there another way to do this that I'm missing?
 
Sure, I'm trying to remove a pair of tags if an option box is checked.

Template is member_tooltip

regex is /<xf:profilebanner.*>|<\/xf:profilebanner>/

to match both the opening tag or the closing tag:

<xf:profilebanner user="$user" size="m" class="memberTooltip-header" toggle="memberTooltip--withBanner">
</xf:profilebanner>

The replace is as follows, to display nothing if the option box is true, removing the tags, or to leave them in, if it's false.

Code:
<xf:if is="{$xf.options.enable_profile_cover_above_info_on_tooltip}">
        <xf:else />
        $0
        </xf:if>

Test seems okay:

1607634066385.png



1607634080165.png


However I don't think it likes me trying to wrap the opening and closing tags in another set of xf tags individually.

Line 17: Template tags are not well formed. Tag if was found when expecting profilebanner. - Template modifications: public:member_tooltip

Hence, I'm not sure if there's an easy way to test for the if condition before even attempting to let a template conditional apply, as it works fine without the condition, or if I need to completely rethink my regex so I can use the conditional
 
Okay, I think I figured it out. Still figuring out what regex could do.

I changed the approach to find everything between the two tags and work with that instead and kept the templater happy.

Using regex to capture everything between the tags, and tags themselves, and using that content within the condition.

Find /<xf:profilebanner.*>([\s\S]*?)<\/xf:profilebanner>/

Replace

Code:
<xf:if is="{$xf.options.enable_profile_cover_above_info_on_tooltip}">
$1
<xf:else />
$0
</xf:if>
 
Back
Top Bottom