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

XenForo Conditionals Issue

Discussion in 'XenForo Development Discussions' started by silence, Jan 20, 2014.

  1. silence

    silence Well-Known Member

    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. Vincent Gabriel

    Vincent Gabriel Active Member

    Is this an admin template or part of an admin template modification?
     
  3. silence

    silence Well-Known Member

    Public template, fine sir!
    And I'm calling this template via a template modification.
     
  4. Chris D

    Chris D XenForo Developer Staff Member

    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.
     
  5. silence

    silence Well-Known Member

    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. Vincent Gabriel

    Vincent Gabriel Active Member


    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>
     
  7. silence

    silence Well-Known Member

    Yeah I can't say the same. Did you try placing the template with a template modification?
     
  8. silence

    silence Well-Known Member

    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>
     

Share This Page