Problems, need help? Have a tip or advice? Post it here.
7 posts Page 1 of 1
Greetings.

I was wondering how it will be possible to integrate a <cms:if> statement with an editable region with multiple potential values?

For example, say in my <cms:template> i have
Code: Select all
<cms:editable name='options' label='Options' desc='Select some options' type='checkbox' opt_values='apple | banana | orange | pear | grape'></cms:editable>

What sort of if statement would I use to determine which checkboxes are selected? I want to display a particular block of code depending on which checkbox or boxes are selected. Here's a sort of idea of what I want here (code not functional):
Code: Select all
<cms:if options='apple'>
  <p>You picked an apple</p>
</cms:if>
<cms:if options='banana'>
  <p>You picked a banana </p>
</cms:if>
<cms:if options='orange'>
  <p>You picked an orange </p>
</cms:if>
<cms:if options='pear'>
  <p>You picked a pear </p>
</cms:if>
<cms:if options='grape'>
  <p>You picked a grape</p>
</cms:if>


This works fine if the user only selects one option, but I need to also handle if the user selects multiple options, unfortunately it just returns separated values.
How can I get this to work?
TIA!
Hi,

To iterate through the values contained in a checkbox, we need to use the <cms:each> tag (http://docs.couchcms.com/tags-reference/each.html).

For example, please try the following -
Code: Select all
<cms:each options as='opt'>
    <cms:if opt='apple'>
        <p>You picked an apple</p>
    </cms:if>
    <cms:if opt='banana'>
        <p>You picked a banana </p>
    </cms:if>
</cms:each>

Hope it helps.
Aha thank you! I was a little confused by how to implement that 'each' tag. Thanks!
So I've tried out the each tag. Is it possible to mix the <if> inside the each with an <else>? I'm trying to do it with the above example however it just outputs ALL the possibilities.
So for example

Code: Select all
<cms:each options as='opt'>
    <cms:if opt='apple'>
        <p>You picked an apple</p>
   <cms:else/>
        <p>You didn't pick an apple</p>
    </cms:if>
    <cms:if opt='banana'>
        <p>You picked a banana </p>
   <cms:else/>
        <p>You didn't pick a banana </p>
    </cms:if>
</cms:each>

The above code for me will output something along the lines of
Apple:
You picked an apple
You didn't pick a banana
Banana:
You picked an apple
You didn't pick a banana

However I'm trying to keep the responses isolated, ie. Apple should only display parameters relevant to Apple and not things applicable to banana.

Please let me know if I should rather post the actual code that I am working on as it is a slightly different (same concept, just a few extra div's etc inside, perhaps I'm overlooking something).

TIA!
Please post some sample output corresponding to various selections e.g. apple+banana, apple+orange, only apple etc.
No need to post what code you are trying to use to get that output - just the desired output.
Thanks for the response KK.

What I'm trying to do is let the user pick a selection of checkboxes in the CMS. On the fronted each checkbox corresponds to a DIV which displays a specific value if the checkbox is checked, or a default value if the checkbox is not checked.
For example in the CMS there are checkboxes,
Fruits:
Apple
Banana
Pear
Grape

On the front end there is a block of code for each fruit
Apple Banana Pear Grape
Default Default Default Default

if the checkbox is selected for all fruit, it would display
Apple Banana Pear Grape
Selected Selected Selected Selected

If its just for apple + banana
Apple Banana Pear Grape
Selected Selected Default Default

etc etc.

(The problem i was having is it would draw on my front end (for say just apple + banana):
Apple Banana Pear Grape
Selected Default Default Default
Apple Banana Pear Grape
Default Selected Default Default
Apple Banana Pear Grape
Default Default Default Default
Apple Banana Pear Grape
Default Default Default Default)

TIA!
OK, I get it now.
Please provide me with the actual HTML code you have on the frontend and I'll let you know how to set the values the way you want.
7 posts Page 1 of 1

Who is online

In total there are 3 users online :: 1 registered, 0 hidden and 2 guests
(based on users active over the past 5 minutes)

Users browsing this forum: Google [Bot] and 2 guests