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

XenForo Conditionals Issue

silence

Well-known member
#1
So I'm using something like this in my template:
HTML:
<xen:if is="{$data.istheredata}">
    <xen:if is="{$xenOptions.data_position} == 'default'">
        <ol class="messageSimpleList" id="ProfilePostList">
    <xen:else />
        <ol class="profilepost" style="<xen:if is="{$data.istherecontent}">display: inline;<xen:else />display: none;</xen:if>">
    </xen:if>
</xen:if>
    <li id="submit">
        <a href="submit.com">Submit</a>
    </li>
</ol>
It submits just fine, however when I go to the page with said template, it's completely messed up. It seems the <ol> tag isn't closed and I'm not sure why.
Can someone tell me why this should, or should not be happening? D:

Thanks!
 
#2
So I'm using something like this in my template:
HTML:
<xen:if is="{$data.istheredata}">
    <xen:if is="{$xenOptions.data_position} == 'default'">
        <ol class="messageSimpleList" id="ProfilePostList">
    <xen:else />
        <ol class="profilepost" style="<xen:if is="{$data.istherecontent}">display: inline;<xen:else />display: none;</xen:if>">
    </xen:if>
</xen:if>
    <li id="submit">
        <a href="submit.com">Submit</a>
    </li>
</ol>
It submits just fine, however when I go to the page with said template, it's completely messed up. It seems the <ol> tag isn't closed and I'm not sure why.
Can someone tell me why this should, or should not be happening? D:

Thanks!
Is this an admin template or part of an admin template modification?
 

Chris D

XenForo developer
Staff member
#4
I hope you don't mind me saying, but that code is very clunky. HTML is supposed to be nested correctly. Your code is kind of like this, in a way, if you pretend the <xen:if> tags are real HTML:

<div>
<h3> This is the title</div>
</h3>

That wouldn't be valid in HTML, so using the <xen:if> tags in a similar way may be the reason it isn't compiling correctly.

Try and restructure your code somewhat. Even if it means having two distinct and complete <ol></ol> blocks inside the conditional, rather than half inside and half outside.

Also, using <xen:if></xen:if> inline is quite a bad idea.

For basic if/else conditionals inline within other HTML use the curly if syntax, e.g.

Code:
<div class="bananas {xen:if $apples, 'apples', 'oranges'}">

</div>
It's easier to type, easier to read, and more likely to work as expected.
 

silence

Well-known member
#5
I hope you don't mind me saying, but that code is very clunky. HTML is supposed to be nested correctly. Your code is kind of like this, in a way, if you pretend the <xen:if> tags are real HTML:

<div>
<h3> This is the title</div>
</h3>

That wouldn't be valid in HTML, so using the <xen:if> tags in a similar way may be the reason it isn't compiling correctly.

Try and restructure your code somewhat. Even if it means having two distinct and complete <ol></ol> blocks inside the conditional, rather than half inside and half outside.

Also, using <xen:if></xen:if> inline is quite a bad idea.

For basic if/else conditionals inline within other HTML use the curly if syntax, e.g.

Code:
<div class="bananas {xen:if $apples, 'apples', 'oranges'}">

</div>
It's easier to type, easier to read, and more likely to work as expected.
It's fine haha I rather know there's a problem then pretend it's all okay.
The inline conditional is very helpful, but this is the only spot in the addon where it's this wacky, so I think I'll just leave the base code in the template and move the conditional into 2 new templates to simplify everything. Only one is loaded at a single instance so should work out okay :)
 
#6
I hope you don't mind me saying, but that code is very clunky. HTML is supposed to be nested correctly. Your code is kind of like this, in a way, if you pretend the <xen:if> tags are real HTML:

<div>
<h3> This is the title</div>
</h3>

That wouldn't be valid in HTML, so using the <xen:if> tags in a similar way may be the reason it isn't compiling correctly.

Try and restructure your code somewhat. Even if it means having two distinct and complete <ol></ol> blocks inside the conditional, rather than half inside and half outside.

Also, using <xen:if></xen:if> inline is quite a bad idea.

For basic if/else conditionals inline within other HTML use the curly if syntax, e.g.

Code:
<div class="bananas {xen:if $apples, 'apples', 'oranges'}">

</div>
It's easier to type, easier to read, and more likely to work as expected.
It's fine haha I rather know there's a problem then pretend it's all okay.
The inline conditional is very helpful, but this is the only spot in the addon where it's this wacky, so I think I'll just leave the base code in the template and move the conditional into 2 new templates to simplify everything. Only one is loaded at a single instance so should work out okay :)

Just testing this worked for me.

Code:
<xen:if is="true">
    <xen:if is="'def' == 'default'">
        <ol class="messageSimpleList" id="ProfilePostList">
    <xen:else />
        <ol class="profilepost" style="<xen:if is="true">display: inline;<xen:else />display: none;</xen:if>">
    </xen:if>
</xen:if>
    <li id="submit">
        <a href="submit.com">Submit</a>
    </li>
</ol>
 

silence

Well-known member
#7
Just testing this worked for me.

Code:
<xen:if is="true">
    <xen:if is="'def' == 'default'">
        <ol class="messageSimpleList" id="ProfilePostList">
    <xen:else />
        <ol class="profilepost" style="<xen:if is="true">display: inline;<xen:else />display: none;</xen:if>">
    </xen:if>
</xen:if>
    <li id="submit">
        <a href="submit.com">Submit</a>
    </li>
</ol>
Yeah I can't say the same. Did you try placing the template with a template modification?
 

silence

Well-known member
#8
This seemed to work for me, still messy though:
HTML:
<xen:if is="'def' == 'default'">
    <ol class="messageSimpleList" id="ProfilePostList">
<xen:else />
    <ol class="profilepost" style="<xen:if is="true">display: inline;<xen:else />display: none;</xen:if>">
</xen:if>

    <xen:if is="true">
        // stuff
    </xen:if>

    <li id="submit">
        <a href="submit.com">Submit</a>
    </li>
</ol>