Forum for discussing general topics related to Couch.
6 posts Page 1 of 1
hi,

i'm new to couch and i'm looking for some tips on how to approach the fallowing:

header [dynamic]
file name - (file size) [dynamic]
file name - (file size) [dynamic]

header [dynamic]
file name - (file size) [dynamic]
file name - (file size) [dynamic]
file name - (file size) [dynamic]

header [dynamic]
file name - (file size) [dynamic]

as one can see everything is dynamic, meaning the user should be able to define for themselves the headers, file names and file sizes.

i started to use a repeatable region, but then quickly realized that it would not work unless they can be nested. unfortunately it looks like that is not possible.

any suggestions will be greatly appreciated
This is a tricky one because, as you noticed, we cannot nest repeatable regions - ideally the 'Header' field should have the other two fields carrying file info nested within it.

However, if you are ready to put up with some duplicate content we can still use repeatable regions by adding the 'Header' field to each row (thus each row representing a file also carries its header's info with it)

This is the definition:
Code: Select all
   <cms:repeatable name='test' >
       <cms:editable type='text' name='header' label='Header'  />
       <cms:editable type='text' name='file_name' label='File Name'  />
       <cms:editable type='text' name='file_size' label='File Size'  />
    </cms:repeatable>

which results in a grid like this:
scr.jpg
scr.jpg (34.54 KiB) Viewed 2614 times

Finally this is how we can list the files grouped under the headers:
Code: Select all
<cms:show_repeatable 'test' >
    <cms:if cur_header != header>   
        <cms:set cur_header=header />
        <h3><cms:show header /></h3>
    </cms:if>   
    <cms:show file_name /> - (<cms:show file_size />)<br />
</cms:show_repeatable>

The code above results in:
scr1.png
scr1.png (3.13 KiB) Viewed 2614 times

A more complex listing with UL/LI can be done as follows:
Code: Select all
<ul>
<cms:show_repeatable 'test' >
    <cms:if cur_header != header>
        <cms:if cur_header != ''>
            </ul></li>
        </cms:if>
        <cms:set cur_header=header />
        <li><cms:show header />
        <ul class="sub-menu">
    </cms:if> 
    <li><cms:show file_name /> - (<cms:show file_size />)</li>
</cms:show_repeatable>
</ul></li></ul>

which results in:
scr2.png
scr2.png (2.3 KiB) Viewed 2614 times

Hope this helps.
:D thank you very much. that would have to do till there is support for nested repeatable regions.
do you think you would implement it in the future? would be great to have.
do you think you would implement it in the future? would be great to have

It certainly would be a very useful thing. In fact I had that in mind while coding the current version and had implemented almost 90% of it when I ran into some intractable architectural issues (primarily because the repeatable regions actually piggy-back upon the older editable regions which have no notion of getting repeated).

So, will I implement them in the future? Doesn't seem likely, I am afraid, as I've already tried that and failed. Might happen if there is a rewrite of the base code sometime in the future. Cannot say.
@kk: thanx for the heads up. i hope you that it does show up in a future version, it's really needed.

btw: i don't think you failed at implementing, it's just a minor setback :)

ah —something like this would also be handy: <cms:if !(my_var) >
It is a very old post but apparently people are still referring to it so here is a later solution (actually even this has been available for several years now) -

A repeatable-region still cannot be nested within another repeatable-region *but* we can nest it within a 'mosaic' instead (viewtopic.php?f=5&t=11105 see '4. Mosaic').

The revised code would now become -
Code: Select all
<cms:mosaic name='content' label='Content'>
    <cms:tile name='item' label='Item'>
        <cms:editable type='text' name='header' label='Header'  />
       
        <cms:repeatable name='info' label='File Info' >
            <cms:editable type='text' name='file_name' label='File Name'  />
            <cms:editable type='text' name='file_size' label='File Size'  />
        </cms:repeatable>
    </cms:tile>
</cms:mosaic>

This will yield something like the following in the admin-panel -
mosaic.png
mosaic.png (23 KiB) Viewed 321 times

On the front-end, we can use the following example code for simple listing -
Code: Select all
<cms:show_mosaic 'content'>
    <cms:if k_tile_name='item' >
        <h3><cms:show header /></h3>
        <cms:show_repeatable 'info' >
            <cms:show file_name /> - (<cms:show file_size />)<br>
        </cms:show_repeatable>
    </cms:if>
</cms:show_mosaic>

Which yields -
scr1.png
scr1.png (7.24 KiB) Viewed 321 times

Or for a more complex output -
Code: Select all
<ul class="list">
    <cms:show_mosaic 'content'>
        <cms:if k_tile_name='item' >
            <li>
                <strong><cms:show header /></strong>
                <ul>
                    <cms:show_repeatable 'info' >
                        <li><cms:show file_name /> - (<cms:show file_size />)</li>
                    </cms:show_repeatable>
                </ul>
            </li>
        </cms:if>
    </cms:show_mosaic>
</ul>

Which yields -
scr2.png
scr2.png (5.48 KiB) Viewed 321 times

Hope this helps.
6 posts Page 1 of 1
cron