0

I've been trying to set up a conditional that will display a notification message if there are no entries in the grid. Like this

{if mygrid:total_rows != "0"} 
<h6> Title </h6>
  {mygrid}
     <p>{mygrid:title}</p>
  {/mygrid} 
{if:else}
<h2>ERROR</h2>
{/if}

However when there are 0 rows the conditional does not execute the ERROR message. I output {mygrid:total_rows} and displays 0 for no rows and 1,2,3... etc if there are entries. If there are grid rows the grid content is displayed.

I'm not sure why the conditional won't execute {if:else}

Even something like won't execute

 {if mygrid:total_rows == "0"} 
  <p> MESSAGE </p>
{/if}
2
  • Did you try {if '{mygrid:total_rows}' == "0"} Mar 19, 2015 at 16:03
  • tried {if '{mygrid:total_rows}' != "0"} but did not work Mar 20, 2015 at 2:24

1 Answer 1

1

I've had very odd problems with grids and total_rows, especially if you have multiple grid fields in the template with multiple conditionals throughout checking for total_rows.

I tried numerous conditionals to get round the problem and oddly, something that would be working, suddenly stopped when adding another conditional in the template, which must be related to an EE conditional bug.

What seems to work consistently is:

{if mygrid:total_rows > 0}...{if:else}...{/if}

Another technique albeit clunky:

{if "{mygrid limit=1}has content{/mygrid}" != ""}...{if:else}...{/if}

If you still have issues, check other conditionals in the template.

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.