Page 1 of 1

[SOLVED] Products module - show icons if selected option is 'true'

Posted: Thu May 07, 2009 8:28 am
by ukmgranger
Hi there,

I am using the products module to build a database of campsites that allow campfiers in the UK.  You can see it here:
http://www.campfires-allowed.co.uk

I have a set of custom fields set up as check boxes which I want to use to show an icon on the products page if it is set to true.

The code below shows what I have done for this, but it isn't working quite right.  Basically the code below shows the icon if there is ANY value in the checkbox - true or false.

How would I have it only display the icon when the value is 'true'?

Code: Select all

{if $entry->fields.CaravansAllowed->value}
<div class="icon">
<img src="uploads/images/iconCaravan.png" alt="Caravans Allowed" width="38" height="38" />
</div>
{/if}
Thanks in advance people.:)

Re: Products module - show icons if selected option is 'true'

Posted: Thu May 07, 2009 2:16 pm
by jmcgin51
ukmgranger wrote: Hi there,

I am using the products module to build a database of campsites that allow campfiers in the UK.  You can see it here:
http://www.campfires-allowed.co.uk

I have a set of custom fields set up as check boxes which I want to use to show an icon on the products page if it is set to true.

The code below shows what I have done for this, but it isn't working quite right.  Basically the code below shows the icon if there is ANY value in the checkbox - true or false.

How would I have it only display the icon when the value is 'true'?

Code: Select all

{if $entry->fields.CaravansAllowed->value}
<div class="icon">
<img src="uploads/images/iconCaravan.png" alt="Caravans Allowed" width="38" height="38" />
</div>
{/if}
Thanks in advance people.:)
Just a guess (untested):

Code: Select all

{if $entry->fields.CaravansAllowed->value == "1"}
<div class="icon">
<img src="uploads/images/iconCaravan.png" alt="Caravans Allowed" width="38" height="38" />
</div>
{/if}

Re: [SOLVED] Products module - show icons if selected option is 'true'

Posted: Thu May 07, 2009 3:58 pm
by ukmgranger
Thanks jmcgin51! :)

Your solution was close enough - it is the syntax that I don't understand yet.  The solution for me was:

Code: Select all

{if $entry->fields.CaravansAllowed->value == "true"}
<div class="icon">
<img src="uploads/images/iconCaravan.png" alt="Caravans Allowed" width="38" height="38" />
</div>
{/if}
I just had to replace "1" for "true".

Thanks again

Re: [SOLVED] Products module - show icons if selected option is 'true'

Posted: Thu May 07, 2009 4:01 pm
by jmcgin51
great!  I almost wrote "true", but decided you could probably substitute "1".  Now that I'm thinking about it, I think removing the quotes around the "1" would make it work that way.

Anyway, glad to help!