ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Conditional operators with string data that may include spaces and quotes

July 31, 2014 9:43am

Subscribe [2]
  • #1 / Jul 31, 2014 9:43am

    biblio

    9 posts

    My templates have a lot of code that needs to look and see if a field is empty or not, and I’m currently trying:

    {if '{big-fat-field}' != ''"}{big-fat-field}{/if}

    and

    {if big-fat-field != ''}{big-fat-field}{/if}


    but if the “big-fat-field” has quoted test in it, the conditionals blow with a PHP error in the library/Functions.php eval process as the quotes are not getting converted.  I see in the documentation that the quotes are supposed to auto-removed, but I’m not seeing that consistently happening.  The tech note on that page suggests that “If you are testing against a word, you should enclose the word in single or double-quotes.”  Should I do this with a string?

    Alternatively, is there a plugin/feature that I could use that is closer to PHP’s empty or strlen that doesn’t care about string content?

    Thanks for any help you can provide,

    M.

  • #2 / Jul 31, 2014 10:01am

    Rob Allen

    3105 posts

    If the field is either empty or has anything in it you could simplify the conditional:

    {if big-fat-field}{big-fat-field}{/if}

    ...so if there is any content output the value, if not do nothing

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

ExpressionEngine News!

#eecms, #events, #releases