Not a bug <xf:explain> inside of <xf:if> does not work: "Tag if contains an unexpected child element."

nocte

Well-known member
Affected version
2.0.9
I suppose this is a bug. Here's my use case:

Template modification for admin template user_edit (inside the privacy_select macro).

If I add a <xf:explain> with some text after the last <xf:option> Tag, it works. If I wrap this tag inside an <xf:if> Tag, i get this error:
Tag if contains an unexpected child element.

So this works:
HTML:
<xf:macro name="privacy_select" arg-name="!" arg-label="!" arg-user="!" arg-hideEveryone="{{false}}">
    <xf:selectrow name="privacy[{$name}]" value="{$user.Privacy.{$name}}"
        label="{$label}">

        <xf:option value="none">{{ phrase('nobody') }}</xf:option>
        <xf:if is="!$hideEveryone">
            <xf:option value="everyone">{{ phrase('all_visitors') }}</xf:option>
        </xf:if>
        <xf:option value="members">{{ phrase('members_only') }}</xf:option>
        <xf:option value="followed">{{ phrase('people_x_follows', {'name': ($user.username ? $user.username : '[' . phrase('user') . ']')}) }}</xf:option>

        <xf:explain>Some text</xf:explain>

    </xf:selectrow>
</xf:macro>

And this gives me the error:
HTML:
<xf:macro name="privacy_select" arg-name="!" arg-label="!" arg-user="!" arg-hideEveryone="{{false}}">
    <xf:selectrow name="privacy[{$name}]" value="{$user.Privacy.{$name}}"
        label="{$label}">

        <xf:option value="none">{{ phrase('nobody') }}</xf:option>
        <xf:if is="!$hideEveryone">
            <xf:option value="everyone">{{ phrase('all_visitors') }}</xf:option>
        </xf:if>
        <xf:option value="members">{{ phrase('members_only') }}</xf:option>
        <xf:option value="followed">{{ phrase('people_x_follows', {'name': ($user.username ? $user.username : '[' . phrase('user') . ']')}) }}</xf:option>

        <xf:if is="$condition">
            <xf:explain>Some text</xf:explain>
        </xf:if>

    </xf:selectrow>
</xf:macro>
 
Jeremy is correct. If the contents of the explain tag are empty then it won’t render so the conditional inside the explain tag should sort it.
 
o.k. Thank you, I have already done this workaround.

And with a contentcheck I should be able to avoid an empty explain-area in the html output.

Edit: No, contentcheck also required an if-conditon. :confused:
 
Last edited:
The explain shouldn't be rendered if the text inside is empty, so I think it should be okay without it.
 
Hmm, that looks like a bug then.

It looks like \XF\Template\Templater::processAttributeToRaw() only checks for a completely empty string. It should probably trim the string first to ensure whitespace doesn't count.

I've created a separate bug report.
 
Last edited:
Top Bottom