Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
I have a blog-page where I sometimes want to add this slider.
I've created a template with the following regions:

- blog image
- blog image title
- blog content
- repeatable region for a slideshow
- caption for slideshow

The code to show the slider looks like this:
Code: Select all
<div class="royalSlider rsDefault">
    <cms:show_repeatable 'foto_slideshow' >
        <img class="rsImg" src="<cms:show my_slideshow_image />" alt="" />
        <p><cms:show image_caption /></p>
    </cms:show_repeatable>
</div>


A repeatable region is always visible in the admin panel which means the slider is loaded even when it doesn't contain an image like this:

Code: Select all
<div class="royalSlider rsDefault">
   
</div>


What do I need to add to the code so the slider is only visible when an image is added to the repeatable region?
Hi Gizmo,

It is not uncommon to encounter similar situations where the output of some outer HTML depends on the content to follow.

For such cases, Couch has a very useful technique of delaying the output by 'buffering' it.
Once we have executed the code that is supposed to produce the inner content, we can then choose to output the buffer depending on whether or not there is any inner content.

Our Aurelias tutorial actually demonstrated this technique while outputting he social profile links (http://www.couchcms.com/docs/tutorials/ ... -form.html).

We can use the same technique to handle your case.
We have two ways of implementing the buffering - I'll illustrate both.
1.
Code: Select all
<cms:capture into='my_slideshow'>
    <div class="royalSlider rsDefault">
        <cms:show_repeatable 'foto_slideshow' >
            <cms:if "<cms:not_empty my_slideshow_image />" >
                <img class="rsImg" src="<cms:show my_slideshow_image />" alt="" />
                <p><cms:show image_caption /></p>
               
                <cms:set has_image='1' 'global' />
            </cms:if>
        </cms:show_repeatable>
    </div>
</cms:capture>

<cms:if has_image >
    <cms:show my_slideshow />
</cms:if>

2.
Code: Select all
<cms:capture into='my_slideshow'>
    <cms:show_repeatable 'foto_slideshow' >
        <cms:if "<cms:not_empty my_slideshow_image />" >
            <img class="rsImg" src="<cms:show my_slideshow_image />" alt="" />
            <p><cms:show image_caption /></p>
        </cms:if>
    </cms:show_repeatable>
</cms:capture>

<cms:if "<cms:not_empty my_slideshow />" >
    <div class="royalSlider rsDefault">
        <cms:show my_slideshow />
    </div>
</cms:if>

Take your pick.
Hope this helps.
You did it again! Thanks a lot :D
Can you tell me something CouchCMS can't do? ;)
3 posts Page 1 of 1