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.

How to show a custom field only if value exists

July 11, 2008 2:44am

Subscribe [3]
  • #1 / Jul 11, 2008 2:44am

    plurky

    7 posts

    Dear all:

    I’m creating a custom field (text area) called Opinion.

    Opinion
    Blah blah blah blah

    I want to display this ONLY if the field is filled (ex. blah blah blah) - if blank then don’t show. How do I do this?

    I looked under conditional and global var in doc but it seemed to focus on member or member groups.

    thank you,
    Plurky

  • #2 / Jul 11, 2008 5:17am

    Andy Harris

    958 posts

    It should be as simple as saying:

    {if {custom_field} != ""}show the field here{/if}
  • #3 / Jul 11, 2008 6:07am

    Ingmar

    29245 posts

    Actually, this should probably be:

    {if custom_field != ""}show the field here{/if}

    i.e. no curly braces.

  • #4 / Jul 11, 2008 6:18am

    Andy Harris

    958 posts

    Amazingly, I always get that wrong when I’m coding it and have to change it - clearly it happens to so often that my brain can’t understand which way is actually correct.

  • #5 / Jul 11, 2008 6:23am

    Ingmar

    29245 posts

    If you do use braces you should probably also use quotes, but that is almost never necessary, and in fact not recommended, as EE will be able to do less sanity checking that way. Not saying it’s necessarily a big risk, but still you should avoid it if you can.

  • #6 / Jul 11, 2008 12:01pm

    plurky

    7 posts

    worked like a charm, thank you!

  • #7 / Jul 11, 2008 12:28pm

    Lisa Wess

    20502 posts

    For more of an explanation on the correct syntax, see global conditionals and troubleshooting conditionals.  Good reads. =)

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

ExpressionEngine News!

#eecms, #events, #releases