We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

how to check if grid field is empty

How Do I?

captainahab's avatar
captainahab
22 posts
10 years ago
captainahab's avatar captainahab

I just need to check if one field artist_gallery:image in a grid field is set, if not the markup should not be rendered. This syntax {if "{artist_gallery:total_rows}” > 0} or {if artist_gallery:total_rows > 0} is not working … if there is no image, the markup is rendered.

Any ideas? Thank you!

{if "{artist_gallery:total_rows}" > 0}
 <div id="artistgallery">
  <div class="cycle-slideshow">
   {artist_gallery}
    {artist_gallery:image}
   {/artist_gallery}
  </div>
  <div id="adv-custom-pager" ></div>
  <div class="clb"></div>
 </div>
{/if}
       
Riverboy's avatar
Riverboy
2,993 posts
10 years ago
Riverboy's avatar Riverboy

I have no idea whats the deal with total codes in your template and how you have built it, but have you tried this:

{artist_gallery}
 <div id="artistgallery">
  <div class="cycle-slideshow">
   
    {artist_gallery:image}
  
  </div>
  <div id="adv-custom-pager" ></div>
  <div class="clb"></div>
 </div>
 {/artist_gallery}

Havent tried but it should not show anything if there is no image available?

       
captainahab's avatar
captainahab
22 posts
10 years ago
captainahab's avatar captainahab

That’s the first thing I tried. If no image is present, nothing is present – but if there is more than one image, everything inside {artist_gallery} is rendered for every single image.

       
Riverboy's avatar
Riverboy
2,993 posts
10 years ago
Riverboy's avatar Riverboy

So you want to pull out less markup, and the conditional is working when there is images right?

What about this then, (if your code is working when images available):

{if "{artist_gallery:total_rows}" > 0}
 <div id="artistgallery">
  <div class="cycle-slideshow">
   {artist_gallery}
    {artist_gallery:image}
   {/artist_gallery}
  </div>
  <div id="adv-custom-pager" ></div>
  <div class="clb"></div>
 </div>
{if:else}
FOO and a BAR :blush:
{/if}

I have no idea again, does that produce some sort of conflict…

       
captainahab's avatar
captainahab
22 posts
10 years ago
captainahab's avatar captainahab

Seems the rows of the grid have nothing to do with the objects inside the rows. What ever condition I use, I get strange results – sometimes a second image is rendered outside the gallery container … I’ll try something else. Thank you for your help.

       
Riverboy's avatar
Riverboy
2,993 posts
10 years ago
Riverboy's avatar Riverboy

Yep, sometimes we all need to re-think how-to. Shout out with the results how you finally did it?

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.