Problems, need help? Have a tip or advice? Post it here.
5 posts Page 1 of 1
Goodmorning,

I'm working on a project with Couchcms and I'm facing a problem of which I can't find a solution anywhere, even reading documentation and other troubleshootings.

I have a repeatable region, but I want the div containing the fields to be visible only if there is more than one repeatable row filfilled (in the back-end). The reason I want to achieve this is that if I don't hide it when empty, it shows the encumbrance of the div, keeping a lot of white space.

I already tried with
Code: Select all
<cms:show_repeatable 'sezione_box'>
          <cms:if k_count ge '1'>
             ...
          </cms:if>
</cms:show_repeatable>


And also replacing "k_count" with "k_total_records". Also tried with

Code: Select all
<cms:if "<cms:show_repeatable 'sezione_box' count_only='1' />">
        <div class="row">
          <cms:show_repeatable 'sezione_box'>
             ...
          </cms:show_repeatable>
       </div>
</cms:if>


... None of them worked for me.

_______________________________________

This is what I have got:
Code: Select all
<cms:repeatable name='sezione_box' label='Box' group='box'>
      <cms:editable type='image' name='box_immagine' label='Immagine di sfondo'/>
      <cms:editable type='text' name='box_titolo' label='Titolo del box'/>
      <cms:editable type='text' name='box_testo' label='Testo del box'/>
      <cms:editable type='text' name='box_link' label='Link del box'/>
</cms:repeatable>


Code: Select all
<cms:show_repeatable 'sezione_box'>
            <div class="col-lg-4 col-md-6">
              <div class="content-box-7">
                <a href="<cms:show box_link/>" target="_blank">
                  <div class="content-box-img js-bg js-height square" data-image-src="<cms:show box_immagine/>">
                     <div class="info">
                      <h5 class="text-white"><cms:show box_titolo/></h5>
                      <p class="text-white"><cms:show box_testo/></p>
                    </div>
                  </div>
                </a>
              </div>
            </div>
</cms:show_repeatable>

The part which must be hidden is the one starting just after the <cms:show_repeatable 'sezione_box'> opening tag.

If anyone could give me some advice, it would be a great help!
Thanks in advance!
Good evening! I thought this was a problem I had a while back - have a look at this thread https://www.couchcms.com/forum/viewtopic.php?f=4&t=8044&hilit=repeatable+region+empty - hopefully it'll all make sense and allow you to sort out your issue with empty repeatable regions!
Let me suggest a more laconic solution

Code: Select all

<cms:show_repeatable 'sezione_box'>
    <cms:if k_first_row>

    <!-- Repeatable -->
    <div class="row">
    </cms:if>

        <!-- Element #<cms:show k_count /> -->
        <div class="col-lg-4 col-md-6">
            <div class="content-box-7">
                <a href="<cms:show box_link/>" target="_blank">
                    <div class="content-box-img js-bg js-height square" data-image-src="<cms:show box_immagine/>">
                        <div class="info">
                            <h5 class="text-white"><cms:show box_titolo/></h5>
                            <p class="text-white"><cms:show box_testo/></p>
                        </div>
                    </div>
                </a>
            </div>
        </div>
        <!-- /element #<cms:show k_count /> -->
    <cms:if k_last_row>

    </div>
    <!-- /repeatable -->
    </cms:if>
</cms:show_repeatable>



I used variables k_first_row and k_last_row to make sure row is outputted outside no matter how many elements inside. If repeatable has no elements, wrapping div will not be generated at all.
potato wrote: Good evening! I thought this was a problem I had a while back - have a look at this thread https://www.couchcms.com/forum/viewtopic.php?f=4&t=8044&hilit=repeatable+region+empty - hopefully it'll all make sense and allow you to sort out your issue with empty repeatable regions!


Thanks potato, this worked perfectly! :D
trendoman wrote: Let me suggest a more laconic solution

Code: Select all

<cms:show_repeatable 'sezione_box'>
    <cms:if k_first_row>

    <!-- Repeatable -->
    <div class="row">
    </cms:if>

        <!-- Element #<cms:show k_count /> -->
        <div class="col-lg-4 col-md-6">
            <div class="content-box-7">
                <a href="<cms:show box_link/>" target="_blank">
                    <div class="content-box-img js-bg js-height square" data-image-src="<cms:show box_immagine/>">
                        <div class="info">
                            <h5 class="text-white"><cms:show box_titolo/></h5>
                            <p class="text-white"><cms:show box_testo/></p>
                        </div>
                    </div>
                </a>
            </div>
        </div>
        <!-- /element #<cms:show k_count /> -->
    <cms:if k_last_row>

    </div>
    <!-- /repeatable -->
    </cms:if>
</cms:show_repeatable>



I used variables k_first_row and k_last_row to make sure row is outputted outside no matter how many elements inside. If repeatable has no elements, wrapping div will not be generated at all.


Thanks trendoman for your reply! Anyway, this code doesn't work well for my example... When there are empty repeatable regions, I can still see the ingumbrance of the <div>, and in pages where I have more than one repeatable region, the <div class="row"> isn't outputted at all, so that Bootstrap columns don't stay lined up. :(
Thank you anyway for your time and your answer! :D
5 posts Page 1 of 1
cron