5

Although I can no longer find the reference on the ExpressionEngine forums, I was advised several years ago by Ellislab staff to use:

{if my_custom_field != ""}{/if}

rather than:

{if my_custom_field}{/if}

This has worked well up until now.

After upgrading to ExpressionEngine 2.5.5 from 2.5.2, some of my conditional logic now does not work as expected.

Specifically, results that used to correctly return nothing, now return '0' (zero).

For example, either of the following would return nothing in 2.5.2:

{if my_custom_field != ""}
    {my_custom_field}
{/if}
{if "{my_custom_field}" != ""}
    {my_custom_field}
{/if}

However, now they return '0', which obviously breaks things.

In order to return nothing in ExpressionEngine 2.5.5, I need to do this instead:

{if my_custom_field}
    {my_custom_field}
{/if}

If this behaviour is the new norm, I will need to change all my templates, which will suck.

Can anyone confirm this behaviour on their 2.5.5 install, and know if this is the new norm?

Thanks.

  • 1
    What custom field types are you using? Have you looked in the DB to see what's stored in the data column? – Anna_MediaGirl Jan 23 '13 at 1:00
  • Hi @Anna_MediaGirl - of the two I have noticed this on, one was related to Cartthrob and the other was a Google Maps for EE custom field. Re: DB, the corresponding field_id for the Google Maps data contains: '{"markers":{"total":0,"results":[]},"waypoints":{"total":0,"results":{}},"regions":{"total":0,"results":[]}} ' – Adam George Jan 23 '13 at 6:03
3

I cannot replicate this in EE 2.5.5. I tested all 3 variations OP suggested, plus tried single quotes instead of double quotes. The field I tested it against was a File field.

I believe it just depends on the fieldtype.

  • Hmmm, ok. The only reason I thought it was related to the ne w EE version was that after upgrading EE is when things went wonky. If it depends on the fieldtype, then at least two of them are affected as far as I can see. Thanks for checking, much appreciated! – Adam George Jan 24 '13 at 23:44

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.