1

Using EE v2.4 and Matrix v2.2

I'm trying to check if the matrix '{article_images}' rows are != '0'.

Within the channel:

{if article_images}   
 <div class="left article_image  hide-for-small">
  <ul data-orbit>
    {article_images}
      {exp:ce_img:pair disable_xss_check="yes" src="{image_matrix_image}" width="500" quality="80" allow_scale_larger="yes"} 
       <li>
         <img src="{image_matrix_image}" alt="">
         <div class="caption">
           <p>{image_matrix_cutline}{if image_matrix_byline}<em>  ({image_matrix_byline})</em>{/if}</p>
         </div>
       </li>
      {/exp:ce_img:pair} 
    {/article_images}
 </ul>  
</div>  
{/if}

'{article_images}' never evaluates to false.

I've tried:

{if article_images}   
 {article_images}
 {if '{image_matrix_image}' != '0'}
 <div class="left article_image  hide-for-small">
  <ul data-orbit>
      {exp:ce_img:pair disable_xss_check="yes" src="{image_matrix_image}" width="500" quality="80" allow_scale_larger="yes"} 
       <li>
         <img src="{image_matrix_image}" alt="">
         <div class="caption">
           <p>{image_matrix_cutline}{if image_matrix_byline}<em>  ({image_matrix_byline})</em>{/if}</p>
         </div>
       </li>
      {/exp:ce_img:pair} 
 </ul>  
</div>  
{/if}
{/article_images}
{/if}

Which works as desired but means that the div containing the orbit plugin is displayed within the loop for as many images as exist.

Is there a way to check the number of rows in the matrix prior to entering '{article_images}'?

Thanks for any input.

1

You can use the :total_rows tag in a conditional like this:

{if article_images:total_rows > 0}

    // other code here

{/if}
3
  • Hi Jeremy, Thanks. I've previously attempted this when I found it at pixelandtonic.com but I get a php error when I try to use this without quotes around the 0. Could this be because of the version of matrix I'm using? Dec 7 '13 at 0:08
  • It is possible. There were some changes in the way conditionals are parsed in EE since 2.4. Does it work when you use quotes around the 0? Dec 7 '13 at 17:19
  • Omitting quotes results in a PHP error. Including quotes compiles but returns no boolean values. Dec 12 '13 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.