Page 1 of 1

[RESOLVED] PRODUCTS - Why is this code not working?

Posted: Wed Nov 13, 2013 5:07 am
by Dramatic
I wanted to make the inclusion of EventsManager conditional in my details template, so I added a checkbox field "has_dates" and the following Smarty code:

Code: Select all

{if $entry->fields.has_dates->value == true}
<h3>Upcoming Dates</h3>
{EventsManager status="published"} 
{else}
Availabile at any time: <a href="/contact">Contact Us</a>
{/if}
<!-- 
{$entry->fields.has_dates->value}
-->
EventsManager is still showing for all products regardless of the setting of has_dates. Why?
However,

Re: PRODUCTS + EventsManager - Why is this code not working?

Posted: Wed Nov 13, 2013 8:23 am
by velden
Well, the condition must be true then.

I don't know how the value of a checkbox is stored in that module but if it's a string for example it would always evaluate true.

If it's stored as a string (again, I don't know) you should check for

{if $entry->fields.has_dates->value == 'true'}

Re: PRODUCTS + EventsManager - Why is this code not working?

Posted: Thu Nov 14, 2013 10:55 pm
by Dramatic
You were right - the products module creates strings not boolean variables for checkboxes, as evidenced by the code in the product admin screen:

Code: Select all

 <input type="hidden" name="m1_customfield[field-4]" value="false" />
<input type="checkbox" name="m1_customfield[field-4]" value="true" />
That it might not be a boolean also occurred to me yesterday while I was away from the computer.