if statements not working

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

PHP:
<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?
 
ojZokXT.png
They are setup like this minus the different titles and id's.
 
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.
 
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.
 
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.
 
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.
 
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:

upload_2014-9-25_22-7-25.webp

Code:
<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>

Produces:
upload_2014-9-25_22-8-2.webp

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