2

This seems like it should be a piece of cake, but I'm at a loss.

I have a Matrix field called {the_matrix} which contains two columns {comment} and {image}. And I'm attempting to output the number of images like so: Total Images: 4

The {total_rows} tag is not sufficient on its own because oftentimes there may be a {comment} and no {image}. So essentially, I need to output the number of rows in which the {image} cell is not empty.

I have tried several different things (including the snippets below) to output the number of rows that contain an {image}, but have had no luck.

{the_matrix}
    Total Images: {image}{total_rows}{/image}
{/the_matrix}


{the_matrix}
    Total Images: {image}{field_row_count}{/image}
{/the_matrix}


{the_matrix}
    Total Images: {image:total_rows}
{/the_matrix}

Am I missing something obvious or am I just out of luck?

Thank you.

4

Just attach a filter on the image column to check it isn't empty:

Total Images: {the_matrix:total_rows search:image="not IS_EMPTY"}
1
  • Thank you Ian! Your solution works perfectly. I never imagined that the :total_rows tag could work that way. Makes me wonder how many other functionalities I'm missing with Matrix. – JJ. May 2 '13 at 18:05
0

You can try by using the Increment (http://devot-ee.com/add-ons/increment) plugin like:

{the_matrix}
{if image}
{exp:pvl_increment id="image_count" random}
{/if}
{/the_matrix}

and find the total number of images:

{if {exp:pvl_increment id="image_count" increment="no" random} > 10}
[output]
{/if}

I hope, it would help you.

1
  • Thank you Bhashkar. Your solution looks like it would work just fine, but I think Ian's approach is a bit more direct. I really appreciate your tip though, because I was not familiar with that add-on until you mentioned it. Cheers! – JJ. May 2 '13 at 18:08

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.