Problems, need help? Have a tip or advice? Post it here.
8 posts Page 1 of 1
Dear Couchies!!!

Like most of us have used the Social Networking Icons display only when a value is passed to the textbox. Reading this value, we can display a particular Social Networking Icon.

I wanted to know if we can do that with checkboxes too?

What I am trying to achieve is that, if I have options like:
[ ]HTML [ ]HTML5 [ ]CSS [ ]CSS3 ([ ] => Unchecked Checkbox)

and I check HTML and CSS, like:
[x]HTML [ ]HTML5 [x]CSS [ ]CSS3 ([x] => Checked Checkbox)

then the image corresponding to HTML and CSS should be displayed at the front end. (Pretty very much like the social networking idea.) but, Only image needs to be outputted, I donot require a text or URL.

Can this be done, only using checkboxes?

Regards,
GenXCoders
Image
where innovation meets technology
Hi genxcoders, I generally have to leave troubleshooting to the Couch Aces ... but like to have a go if I can ...

How about?

Code: Select all
<cms:each my_categories as='cat'>

    <cms:set my_category="<cms:show cat  />" />
   
    ... test my_category and take appropriate action ....

</cms:each>


Simply loop through the checkboxes and see if you need to output anything.

Will this work?
@Potato... Thanks for the reply!!!

But can we separately check which checkbox is checked???
cms:each will function as the for each loop.
cms:set will set the variables

how can we set the variables to values of images???


potato wrote: Hi genxcoders, I generally have to leave troubleshooting to the Couch Aces ... but like to have a go if I can ...

How about?

Code: Select all
<cms:each my_categories as='cat'>

    <cms:set my_category="<cms:show cat  />" />
   
    ... test my_category and take appropriate action ....

</cms:each>


Simply loop through the checkboxes and see if you need to output anything.

Will this work?
Image
where innovation meets technology
hello again ...

But can we separately check which checkbox is checked???


Code: Select all
<cms:each my_categories as='cat'>

    <cms:set my_category="<cms:show cat  />" />

    <cms:if "<cms:not_empty my_category />" >
   
          <cms:if my_category = 'HTML' > output HTML image </cms:if>
          <cms:if my_category = 'HTML5' > output HTML5 image </cms:if>
          <cms:if my_category = 'CSS' > output CSS image </cms:if>
          <cms:if my_category = 'CSS3' > output CSS3 image </cms:if>

    </cms:if>


</cms:each>


I am assuming that if the box isn't checked it will be EMPTY.

Maybe this will work?!
Awesome... It worked like a Charm!!!

Thanks a ton Potato!!!
Image
where innovation meets technology
I'm trying to use this but have a weird issue with this code:

Code: Select all
<cms:set blog_item_col_css="col-sm-8 col-md-6" />
<cms:each blog_options as="cat">
    <cms:set option="<cms:show cat />" />
    <cms:if option="Full Width">
        <cms:set blog_item_col_css="col-12" />
        <cms:show "hello" />
    </cms:if>
</cms:each>
<cms:show blog_item_col_css />


This results in the following output "hello col-sm-8 col-md-6" being displayed.

Which means the code to 'set' blog_item_col_css to "col-12" should have been run (hello IS displayed), but the new value is not output.

I'm missing something obvious I suspect.

TY!
@CouchBob, the issue pertains to something known as the 'scope' where a variable is set.

The first place where you set a value for 'blog_item_col_css', the variable gets set in whatever scope that code is executing.
The second place where you set 'blog_item_col_css', we are within the <cms:each> block and so, by default, it gets set in the scope of <cms:each> and thus remains available only to code within that block.

When the code for <cms:each> ends the variable is lost; in the code that starts executing after <cms:each>, the variable that gets found is the one you had set *outside* <cms:each> and hence you see the previously set value.

The answer is to set the variable at a single location. Two ways of doing this -
1. Explicitly set it in 'global' scope at both places in your code e.g.
Code: Select all
<cms:set blog_item_col_css="col-sm-8 col-md-6" scope='global' />
<cms:each blog_options as="cat">
    ...
    <cms:set blog_item_col_css="col-12" scope='global' />
    ...
</cms:each>
<cms:show blog_item_col_css />


2. At the second place, ask the code to skip the default scope and set the variable anywhere it is found above it (i.e. 'parent' scope) -
Code: Select all
<cms:set blog_item_col_css="col-sm-8 col-md-6" />
<cms:each blog_options as="cat">
    ...
    <cms:set blog_item_col_css="col-12" scope='parent' />
    ...
</cms:each>
<cms:show blog_item_col_css />

Hope this helps.
Brill. Sorted. TY!
8 posts Page 1 of 1
cron