0

I've been trying to get a Grid conditional to work (using EE2.10.3) and no matter what I try, it's not working and the page crashes. My grid field is called "projects_video" and I want to output something if it's not empty. Here's what I've been trying so far:

{exp:channel:entries channel="projects"}
     {if projects_video:total_rows >= 1}
          SOME DATA
     {/if}
{/exp:channel:entries}

Also I've tried:

{exp:channel:entries channel="projects"}
     {if "{projects_video:total_rows}" >= 1}
          SOME DATA
     {/if}
{/exp:channel:entries}

And:

{exp:channel:entries channel="projects"}
     {if {projects_video:total_rows} >= 1}
          SOME DATA
     {/if}
{/exp:channel:entries}

And:

{exp:channel:entries channel="projects"}
     {if projects_video}
          SOME DATA
     {/if}
{/exp:channel:entries}

Any ideas?

2 Answers 2

0

If I'm not mistaken you could use the basics of:

{exp:channel:entries channel="projects"}
     {if projects_video}
       {projects_video}
          {projects_video:option}
          {projects_video:option2}
          etc...
       {/projects_video}
     {/if}
{/exp:channel:entries}

The if statement checks that there is something in the Grid field. Note that this will return true even if the user has created a row and put nothing in it.

5
  • Actually, that was the first thing I tried -- sorry I didn't remember to include that in the listing of what I had tried. I've edited now to include that.
    – edward
    Mar 16, 2016 at 0:34
  • It should work but you need to include the grid tags once inside the conditional. Answer updated! Mar 16, 2016 at 2:12
  • You're right that it should work! But unfortunately it doesn't. It doesn't matter what is inside the if statement; it just breaks the thing, and I get "You have an invalid conditional in your template. Please review your conditionals for an unclosed string, invalid operators, a missing }, or a missing {/if}."
    – edward
    Mar 16, 2016 at 2:22
  • Did you check this post: expressionengine.stackexchange.com/questions/27313/… Mar 16, 2016 at 2:34
  • Yes, thanks, I did and tried out what was there, but unfortunately nothing works.
    – edward
    Mar 16, 2016 at 2:59
0

Here's what eventually worked for me:

{exp:channel:entries channel="projects" limit="1" disable="categories|member_data|pagination"}
{if '{projects_test:total_rows}' > '0'}
    {exp:vmg_nested:channel:entries channel="projects" limit="1" disable="categories|member_data|pagination" prefix="test"}
        {projects_test}
            {projects_test:text}
        {/projects_test}
    {/exp:vmg_nested:channel:entries}
{/if}
{/exp:channel:entries}

Note the single quotes around the braces in the "if" statement.

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.