Bug #23759 Accepted

If statements with Fluid toggles don’t work as documented

Version: 4.3.6 Reporter: dgtlmkt

https://docs.expressionengine.com/latest/fieldtypes/fluid.html#toggle-fields

The if statement shown in the document above won’t display the text when the field is toggled to ON. The {content} block must be included in order for the text to appear, like so:

{my_fluid_field}
  {my_fluid_field:my_toggle}
    {if content}
      {content}
      YES there is a toggle value!
    {/if}
  {/my_fluid_field:my_toggle}
{/my_fluid_field}
  • There are some quirks with toggle conditionals depending on your server configuration and/or if the field was added with a default value to existing entries but those entries were not re-saved. We do want to fix this, but you may be able to work around it with either:

    {if content != 0}

    OR

    {if '{content}'}
    Derek Jones
    17th October, 2018 at 12:18pm
  • I appreciate that Derek, thank you. The first didn’t work for me, but the second did, so I’ll run with that one.

    dgtlmkt
    17th October, 2018 at 12:31pm
  • I sent my initial response a little too quickly and had not properly tested.

    {if '{content}'}

    The above always evaluates as true to me, regardless of the toggle’s status. However, this statement works as I expect it to:

    {if '{content}' == '1'}
    dgtlmkt
    17th October, 2018 at 1:39pm
  • Good catch, the reasoning:

    {if '0'}

    Evaluates as TRUE, because that is a non-empty string. If you remove the quotes, however:

    {if {content}}

    Then it’s either

    {if 0}

    or

    {if 1}

    Which evaluate to a boolean in a more intuitive manner.

    Derek Jones
    17th October, 2018 at 2:00pm

You must be signed in to comment on a bug report.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases