Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
I know there has to be a much better way to do this, but I wasn't able to find anything in the forums or documentation on how to do this properly. I have a repeatable region and on every 3,5,7 and so on columns I have to add an opening div tag and on every 2,4,6 etc. columns I have to add an </div> tag. Here is how I have it now (which works sort of), but it obviously won't grow with more than 9 columns.

Code: Select all
<cms:show_repeatable 'team_member' >
                     <cms:if k_count='1' || k_count='3' || k_count='5' || k_count='7' || k_count='9'>
                        <div class="flex row">
                     </cms:if>
                     <div class="col-md-6 padding-bottom-60 clearfix">
                        <div class="doctors-img">
                           <img src="<cms:show team_image />" width="309" alt="<cms:show name />" title="<cms:show name />" class="img-responsive">
                           <cms:show plusdoc />
                           
                        </div>

                        <div class="doctors-detail">
                           <h4><cms:show name /><span><cms:show role /></span></h4>
                           <p><label class="heading">Speciality</label><label class="detail"><cms:show special /></label></p>
                           <p><label class="heading">Bio</label><label class="detail"><cms:show bio /></label></p>
                           <p><label class="heading">More</label><label class="detail"><cms:show more /></label></p>
                        </div>

                     </div>
                        <cms:if k_count='2' || k_count='4' || k_count='6' || k_count='8'>
                        </div><!-- end flex row -->
                     </cms:if>
                        

                  </cms:show_repeatable>

What you need is the cms:mod tag (http://docs.couchcms.com/tags-reference/mod.html).
Your code could be modified as follows and should work just the same for any number of rows (i.e. make groups of two consecutive rows) -
Code: Select all
<cms:show_repeatable 'team_member' >
    <cms:if "<cms:mod k_count '2' />" >
        <div class="flex row">
    </cms:if>
   
    ...
   
    <cms:if "<cms:not "<cms:mod k_count '2' />" />" >
        </div><!-- end flex row -->
    </cms:if>
</cms:show_repeatable>

There is, however, a flaw in your code - if the number of rows happens to be odd (1, 3, 7 etc.), the closing block will not click and so the DIV will remain unclosed.

To handle that, we need to modify the logic to bring in an addition check with the closing tag as follows -
Code: Select all
<cms:show_repeatable 'team_member' >
    <cms:if "<cms:mod k_count '2' />" >
        <div class="flex row">
    </cms:if>
   
    ...
   
    <cms:if "<cms:not "<cms:mod k_count '2' />" />"  || (k_count = k_total_records) >
        </div><!-- end flex row -->
    </cms:if>
</cms:show_repeatable>

Hope it helps.
That is exactly what I was looking for. Mod tags are going to be super helpful. Thank you KK!
3 posts Page 1 of 1
cron