0

I am using a checkbox channel field named "destinations" that allows an entry to have multiple values checked off. I then want other fields from that entry to be displayed if the destinations field contains, rather then == (is equal to). So, an entry that has both Hawaii and New Zealand checked off for the field destination, will show up in either, rather then having to equal both.

So, this works:

{if destination == "Hawaii"}
                <p><strong>{term}</strong> <br /><a href="{site_url}voyages/{program_page_url}">{title}</a></p>
 {/if}

For a destination that only has Hawaii checked off, in the destination field. But, for an entry that has both Hawaii and New Zealand checked off, it won't show.

I tried using the Contains Operator, https://ellislab.com/expressionengine/user-guide/templates/conditionals.html#contains-operator

{if destination *= Hawaii} xyz {/if}

But it causes the page not to load.

I also tried using the http://devot-ee.com/add-ons/pvl-check-if plugin, but that didn't work either.

Any advice greatly appreciated. The page is here:http://www.sea.edu/destinations/destinations_testing

Note for the destinations that don't have any Upcoming Voyages, its because the Voyages go to multiple destinations, so have more than one item checked off for the destinations field.

Thanks.

0

I never used a checkbox field, but I believe they can should be used as variable pair in case of more than one possible option.

So:

{destination}
  {item}
{/destination}

Will return every item checked. In case of two destinations:

Hawaii
New Zealand

You can try to change your template to these data be inside the variable pair or use an embed to pass all data as one single string and keep your previous logic:

{embed="destination/data" destinations="{destination}{item},{/destination}"}

On the embed:

{if embed:destinations *= "Hawaii"}
  <p><strong>{term}</strong> <br /><a href="{site_url}voyages/{program_page_url}">{title}</a></p>
{/if}

I hope it helps. Bye!

0

I actually ended up using Field Pack http://devot-ee.com/add-ons/field-pack, just installed the Checkboxes field and it offered much more flexibility, achieved what I needed. Here is the updated code:

{if '{destinations:selected option="hawaii"}'} 
            <p><strong>{term}</strong> <br /><a href="{site_url}voyages/{program_page_url}">{title}</a></p>
            {/if}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.