Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
Depending on the circumstance that a repeatable region actually contains data, I would like to output some HTML. If the region is empty, it should not show it.

For example, I defined the following repeatable region in the head section:
Code: Select all
<cms:repeatable name='candidate_requirements' label='Requirements' order='5' >
      <cms:editable name='candidate_requirement'
                    height='50'
                    type='textarea' />
  </cms:repeatable>


I then normally output it like this:

Code: Select all
<h3><small>Requirements</small></h3>
<ul>
     <cms:show_repeatable 'candidate_requirements' >
         <li><cms:show candidate_requirement /></li>
       </cms:show_repeatable>
</ul>


However, I would like to show the h3-header "Requirements" only in the case that the repeatable region actually contains data and is not empty.

So far, I tried the following (both candidate_requirement / candidate_requirements), which does not work. The header does not show up, although a data set is available:

Code: Select all
<cms:if "<cms:not_empty candidate_requirement />" >
         <h3><small>Candidate Requirements</small></h3>
</cms:if>


Any idea?
The editable region "candidate_requirement" only exists within its repeatable region. So you need to check for it with the show_repeatable tag open. Something like this.
Code: Select all
<cms:show_repeatable 'candidate_requirements' >
   <cms:if candidate_requirement >
      <h3><small>Requirements</small></h3>
   </cms:if>
</cms:show_repeatable>

<ul>
   <cms:show_repeatable 'candidate_requirements' >
       <li><cms:show candidate_requirement /></li>
    </cms:show_repeatable>
</ul>
@JD, we have had a discussion before about 'buffering' data - viewtopic.php?f=4&t=9061.

You can use that technique to defer showing the H3 heading till you are sure that the rows are not empty.
If you need a concrete example you can see this - viewtopic.php?f=4&t=7146&p=9647

Hope it helps.
Ok, I set it up with a buffer now as recommended by KK.

The problem is that I am using the repeatable region as part of clonable page listed in one view (this is one page to post job descriptions). Let's take the following example:
Code: Select all

<cms:capture into='skills_output' >
          <h3><small>Candidate Skills</small></h3>
                   
                 <ul>
                        <cms:show_repeatable 'candidate_skills' >
                             <cms:if "<cms:not_empty candidate_skill />">
                                <li><cms:show candidate_skill /></li>
                             <cms:set has_skill='1' 'global' />
                          </cms:if>
                        </cms:show_repeatable>
                   </ul>
</cms:capture>

<cms:if has_skill >
         <cms:show skills_output />
</cms:if>



As I have multiple jobs posted in the view, the variable "candidate_skill" and "has_skill" appear logically multiple times on the same page. If no "candidate_skill" is present in any of the posts, the header h3 is not shown. However, if I have just one skill listed in one of the job posts, the header h3 is also shown in all other posts.

Is there a work-around to reliably check only each post individually?
That shouldn't be a problem.

Suppose following is the code in the list-view where you loop through the jobs -
Code: Select all
<cms:pages masterpage='some-template.php' limit='20' >
    .. code for showing repeatable region here ..
</cms:pages>

Just add a line to our original code to set the 'has_skill' variable to '0' as shown below -
Code: Select all
<cms:pages masterpage='some-template.php' limit='20' >

    <!-- begin with the assumption that candidate has no skills -->
    <cms:set has_skill='0' 'global' />
   
    <cms:capture into='skills_output' >
        <h3><small>Candidate Skills</small></h3>

        <ul>
            <cms:show_repeatable 'candidate_skills' >
                <cms:if "<cms:not_empty candidate_skill />">
                    <li><cms:show candidate_skill /></li>
                    <cms:set has_skill='1' 'global' />
                </cms:if>
            </cms:show_repeatable>
        </ul>
    </cms:capture>

    <cms:if has_skill >
        <cms:show skills_output />
    </cms:if>
   
</cms:pages>

This way as a new job is fetched, the 'has_skill' is set to '0'. If that job has non-empty data in repeatable-regions the code ahead will set 'has_skill' to '1' and the cycle will repeat.

Hope it helps.
Now it works. Thanks a lot.
6 posts Page 1 of 1