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

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
Dramatic

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

Post 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,
Last edited by Dramatic on Thu Nov 14, 2013 10:55 pm, edited 1 time in total.
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3497
Joined: Mon Nov 28, 2011 9:29 am

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

Post 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'}
Dramatic

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

Post 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.
Locked

Return to “Modules/Add-Ons”