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

if statements not working

Discussion in 'XenForo Development Discussions' started by rivacom, Sep 25, 2014.

  1. rivacom

    rivacom Active Member

    So I'm just trying to do a basic admin option with a if statement in the template.

    So I setup admin options for check box, boolean, with a default parameter of false.

    In the template I have

    <xen:if is="{$xenOptions.optionOne}">Option 1</xen:if>
    xen:if is="{$xenOptions.optionTwo}">Option 2</xen:if>
    xen:if is="{$xenOptions.optionThree}">Option 3</xen:if>
    So here is the issue. If the check box for option 1 is checked. Option 1, 2 and 3 are displaying. If no options are checked, option 2 is displaying.

    I tried xen:if is="{$xenOptions.optionOne} == true"> but this didn't seem to make a difference. I'm sure it's a silly syntax error im making but can't figure it out. Any help?
  2. Chris D

    Chris D XenForo Developer Staff Member

    Can you screenshot how the options are set up?
  3. rivacom

    rivacom Active Member

    [​IMG] They are setup like this minus the different titles and id's.
  4. Chris D

    Chris D XenForo Developer Staff Member

    The data type of boolean will cast your default value from a string to boolean. Paradoxically, the string 'false' will be cast as boolean true :D

    So the first area of confusion may be that.

    In this context, the default value should be either 0 or 1; 0 == false 1 == true

    Worth noting that after you change that, you will need to change and save your options again. Changing the default value on an existing option doesn't affect the existing value.
  5. rivacom

    rivacom Active Member

    Hmm tried changing them to 0 with the same result. What value is on/off checkbox throwing out? I'm assuming True/False , but maybe it's something different.
  6. Chris D

    Chris D XenForo Developer Staff Member

    On the options page are they checked or unchecked? I edited my post above, changing the default value won't affect the existing value if the option has already been created.
  7. rivacom

    rivacom Active Member

    So i saved everything, unchecked all the options, saved. Option 2 shows up. Went back, checked option 1. All 3 show up.. lol I'm sure it's something on my side but am baffled.
  8. Chris D

    Chris D XenForo Developer Staff Member

    I can't reproduce the same problem.

    If the code and options are as simple as you say, there's not a lot that can go wrong:


    <xen:if is="{$xenOptions.optionOne}">Option 1</xen:if>
    <xen:if is="{$xenOptions.optionTwo}">Option 2</xen:if>
    <xen:if is="{$xenOptions.optionThree}">Option 3</xen:if>

    This may help: Add this to your template:
    {xen:helper dump, $xenOptions.optionOne}
    {xen:helper dump, $xenOptions.optionTwo}
    {xen:helper dump, $xenOptions.optionThree}

Share This Page