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

Fluid field group conditional

How Do I?

Paul Vance's avatar
Paul Vance
123 posts
one year ago
Paul Vance's avatar Paul Vance

I have a fluid field that contains a field group which in turn contains a grid field. I’m trying to show markup conditionally in the template, only when the grid field is populated:

{my_fluid} {my_fluid:my_group} {fields}{my_group:my_grid}{content}{if '{content:total_rows}’ != ‘0’}Show stuff{/if}{/content}{/my_group:my_grid}{/fields} {/my_group:my_fluid} {/my_fluid}

This works perfectly when the grid field has rows, but when it’s left empty for some reason it renders only the {/content} tag on the front end.

Here’s where it gets really weird: if the template has a space between the {fields} tag and {my_group:my_grid} then it works! The conditional content is shown when the grid has rows, and the rogue {/content} tag disappears:

{my_fluid} {my_fluid:my_group} {fields}SPACE HERE{my_group:my_grid}{content}{if '{content:total_rows}’ != ‘0’}Show stuff{/if}{/content}{/my_group:my_grid}{/fields} {/my_group:my_fluid} {/my_fluid}

Note: all of this happens regardless of what I try to show conditionally.

Any idea what’s up here?

       
Sarah93's avatar
Sarah93
12 posts
one year ago
Sarah93's avatar Sarah93

Have you tried wrapping the conditional in a standard EE {if} tag instead? Something like:

{if {my_group:my_grid}{content:total_rows} > 0} Show stuff {/if}

Alternatively, using the {count} variable might give you more predictable results.

       
abigailjohn's avatar
abigailjohn
3 posts
one year ago
abigailjohn's avatar abigailjohn

As I know, the EE template engine may misinterpret the tags when they are tightly packed together. Adding a space helps to clearly delineate the tags, allowing the engine to parse them correctly.

       

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.