I have a Matrix field (parent) in a channel set to have exactly 4 rows. The rows feature a Playa drop-down. These will serve as promotional tiles in the page templates to cross-promote other pages in the site

In the templates I must always display 4 tiles so need to write a fallback so if only 3 are selected then 1 extra random tile is shown, if only 2 are selected then 2 extra random tiles are shown, etc.

I've got this working fine using the Search parameter, eg:

{parent search:child="not IS_EMPTY"}

However, the problem I'm experiencing is what to do if no options are selected (i.e. all Playa fields/rows are empty). Ideally would be able to do an {if no_results} conditional but can't access from within the {parent} loop and because using search cannot access via a {if parent:total_rows==0} conditional.

Any thoughts?

2 Answers 2


You can use the search:col_name= parameter in combination with :total_rows:

{if '{parent:total_rows search:child="not IS_EMPTY"}' == 0}

Hope that helps!

  • Thanks Brandon - sadly is returning the following error: Parse error: syntax error, unexpected '}' in /Applications/MAMP/htdocs/np/system/expressionengine/libraries/Functions.php(680) : eval()'d code on line 61 Commented Feb 18, 2013 at 21:47
  • You should be putting that outside your Matrix tag pair (unlike normal no_results tags). There's no syntax errors that I can tell – it's working for me! Maybe the error is coming from another part of your template? Commented Feb 18, 2013 at 22:05
  • Hmmm, if I comment out template is fine (thought wouldn't surprise me). Code sample is outside the Matrix loop) {if '{cross_promotion:total_rows search:destination="not IS_EMPTY"}' == 0}DO THIS{/if} Commented Feb 18, 2013 at 22:08

Thanks Brandon for the relpy. I couldn't get this to work in Matrix without returning a PHP error but was able to achieve the desired effect by using the native ExpressionEngine query module, eg

{exp:query sql="SELECT * FROM exp_matrix_data WHERE col_id_7 != '' && entry_id = '{entry_id}'"}
  {if no_results}
    {embed='embeds/footer-tiles' total_rows='0'}

If trying something similar you might need to run in an embedded template so as not to cause a conflicted {no_results} result!

Hope this helps somebody else!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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