Problems, need help? Have a tip or advice? Post it here.
43 posts Page 4 of 5
I'm back ;)... my studies kept me from finishing this project. I would like to wrap it up now but I guess I'll still encounter some problems.

Got the first one right here:

I want to create a repeat loop within a repeat loop and use both times the k_count variable. Something like this (the code is wrong of course. Just to show what I want to do):

<repeat 3 times>
<show k_count>. Group
<repeat 7 times>
<show k_count>. Item
</repeat>
</repeat>

In the end I would like that I get 3 Groups with 7 Items each. Possible?
>> Possible?
Certainly.
The following snippet
Code: Select all
<cms:repeat count='3'>
   <cms:show k_count /><br />
   <cms:repeat count='4'>
      - <cms:show k_count /><br />
   </cms:repeat>
</cms:repeat>

will output -
Code: Select all
0
- 0
- 1
- 2
- 3
1
- 0
- 1
- 2
- 3
2
- 0
- 1
- 2
- 3
Thanks! Then I'll guess I can save the first k_count in another variable and set it to global, use this in the second repeat so that i can even get:

0
0-1
0-2
0-3
0-4
1
1-1
1-2
1-3
...

?
No need to make the variable global as it will still be within the scope (read between the opening and closing brackets) of the outer 'repeat' tag. Just use a different name for disambiguation e.g.
Code: Select all
<cms:repeat count='3'>
   <cms:show k_count /><br />
   <cms:set outer_count=k_count />
   <cms:repeat count='4'>
      <cms:show outer_count />-<cms:show k_count /><br />
   </cms:repeat>
</cms:repeat>

Output -
Code: Select all
0
0-0
0-1
0-2
0-3
1
1-0
1-1
1-2
1-3
2
2-0
2-1
2-2
2-3
Thanks again!

But I have a new question ;)...
Concerning the checkbox editable region, is there any way to access the selected items separately?

For example you can select 'cheese', 'tomato' and 'noodles'. Cheese and noodles get selected. Now I would like to continue with <cms:if editable_region contains cheese...> and <cms:if editable_region contains noodles..>. But as I see it you'll just get "cheese | noodles" back when you access the regions data.
You can use the each tag to list the constituents (http://www.couchcms.com/docs/tags-reference/each.html).

Say, for example, if your editable region of type checkbox is named 'my_checkbox', you can use
Code: Select all
<cms:each my_checkbox>
    <cms:show item /><br>
</cms:each>

You might also want to check first if anything is selected at all -
Code: Select all
<cms:if my_checkbox >
    <cms:each my_checkbox>
        <cms:show item /><br>
    </cms:each>
</cms:if>

Hope this helps.
KK wrote: You can use the each tag to list the constituents (http://www.couchcms.com/docs/tags-reference/each.html).

[...]


Yeah, but doesn't this just put out the constituents one after another? I'm looking for a way to check if one specific item is selected and react accordingly.

Like you can check "blue", "brown", "yellow", "pink", "black"... if then for example blue and yellow is selected I want to be able to say "if blue: draw me a blue line", "if yellow: draw me a yellow one as well".
Assuming the editable region is configured with opt_values='blue | brown | yellow | pink | black', both the snippets below will do just that -
Code: Select all
<cms:if my_checkbox > 
   <cms:each my_checkbox>

      <cms:if item='blue'>
         draw me a blue line<br>
      </cms:if>

      <cms:if item='brown'>
         draw me a brown line<br>
      </cms:if>

      <cms:if item='yellow'>
         draw me a yellow line<br>
      </cms:if>

      <cms:if item='pink'>
         draw me a pink line<br>
      </cms:if>

      <cms:if item='black'>
         draw me a black line<br>
      </cms:if>     

   </cms:each>
</cms:if>

Or simply -
Code: Select all
<cms:if my_checkbox > 
   <cms:each my_checkbox>
      draw me a <cms:show item /> line<br>
   </cms:each>
</cms:if>

The values are there available for you. It really is up to you as to how you use them.
If you have some specific requirement, post it in and I'll try to work out the solution.
This helped a lot, thanks!
43 posts Page 4 of 5