Forum for discussing general topics related to Couch.
5 posts Page 1 of 1
Hi

I am trying to show different code/content if a value is empty, I have the following but think I have done it wrong

There is values/content in the slideshow so thought with the following code, it would show the still image if the slideshow content was empty but it's not showing the slideshow even though it has content. Can anyone help please as bit lost.

Code: Select all
<cms:if "<cms:not_empty slide_image />" >

<section id="main-slider">
    <div class="owl-carousel">
        <cms:show_repeatable 'slides' >
            <div class="item" style="background-image: url(<cms:show slide_image/>);">
                <div class="slider-inner">
                    <div class="container">
                        <div class="row">
                            <div class="col-sm-12 text-center">
                                <div class="carousel-content">
                                    <h2><cms:show slide_heading/></h2>
                                    <cms:show slide_text/>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </cms:show_repeatable>
    </div><!--/.owl-carousel-->
</section><!--/#main-slider-->
   
    <cms:else />
   
    <section id="services">
        <img src="<cms:show static_image/>" alt="">
    </section>
   
    </cms:if>
Update: I done it using enable and disable with the following code if it helps anyone else to do similar thing

Code: Select all
<cms:editable name='slides_group' label='Slideshow Section' type='group' collapsed='1' order='1' />
    <cms:editable name='slides_enable' label='Enable Slideshow Section' opt_values='Enable=1 || Disable=0' type='radio' group='slides_group' order='1' />
    <cms:repeatable name='slides' label='Slides' stacked_layout='1' group='slides_group' order='2'>
        <cms:editable name='slide_image' label='Slideshow Image' type='image' />
        <cms:editable type='text' name='slide_heading' label='Slide Heading' />
        <cms:editable type='richtext' toolbar='full' name='slide_text' label='Slide Text' />
    </cms:repeatable>

    <cms:editable name='static_image_section' label='Still Image Section (If dont want slideshow)' type='group' collapsed='1' order='2' />
    <cms:editable name='still_image_enable' label='Enable Still Image Section' opt_values='Enable=1 || Disable=0' type='radio' group='static_image_section' order='1' />
    <cms:editable name='static_image' label='Still Image' type='image' group='static_image_section' order='2' />

<cms:if "<cms:get_custom_field 'slides_enable'/>">
    <section id="main-slider">
        <div class="owl-carousel">
            <cms:show_repeatable 'slides' >
                <div class="item" style="background-image: url(<cms:show slide_image/>);">
                    <div class="slider-inner">
                        <div class="container">
                            <div class="row">
                                <div class="col-sm-12 text-center">
                                    <div class="carousel-content">
                                        <h2><cms:show slide_heading/></h2>
                                        <cms:show slide_text/>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </cms:show_repeatable>
        </div><!--/.owl-carousel-->
    </section><!--/#main-slider-->
</cms:if>

<cms:if "<cms:get_custom_field 'still_image_enable'/>">
    <section id="services">
        <img src="<cms:show static_image/>" alt="">
    </section>
</cms:if>

@Ianhaney50

I see you have solved the issue. But I am still posting here so that this method might serve as an alternative way to do the same. Please do give it a try, if possible.

Code: Select all
<cms:set display_slideshow="0" scope="global" />
<cms:show_repeatable 'slides'>
    <cms:if k_count ge '1'>
        <cms:set display_slideshow="1" scope="global" />
    </cms:if>
</cms:show_repeatable>
   
<cms:if display_slideshow eq '1'>
    <!-- Displays Slide Show in the IF condition-->
    <section id="main-slider">
        <div class="owl-carousel">
            <cms:show_repeatable 'slides' >
                <!-- Your Code -->
            </cms:show_repeatable>
        </div><!--/.owl-carousel-->
    </section><!--/#main-slider-->
<cms:else_if display_slideshow eq '0' />
    <!-- Displays Static Image in the ELSE condition-->
    <section id="services">
        <img src="<cms:show static_image/>" alt="">
    </section>
</cms:if>


I happen to use this usually, whenever I am posed with the situation as you were. Using the above code, if you may, will work:
1. Even without the editables slides_enable and still_image_enable.
2. Also reducing the need to handle the radios, in case the repeatables are part of a clonable template.

Regards,
GenXCoders
Image
where innovation meets technology
Thank you, I'll give that a go in the next day or 2 and let you know how it goes but does look more cleaner and as you say no need for the radio buttons to enable and disable the sections
@Ianhaney50

Thanks for the revert :D .
Will be looking forward to your implementation feedback.

Regards,
GenXCoders
Image
where innovation meets technology
5 posts Page 1 of 1