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.

Custom field conditional evaluated incorrectly

August 17, 2011 5:13pm

Subscribe [4]
  • #1 / Aug 17, 2011 5:13pm

    Spurlock

    14 posts

    Hello all. I have the following code in my template:

    {if description}{description}
    {if:else}{event_summary}
    {/if}

    The template incorrectly evaluates the first “if” to false even when there is a description present. Not only that, if I leave out the conditional and just write

    {description}
    {event_summary}

    Expressionengine will correctly print out the contents of both fields.

    So… the fields really are filled, and they really have the correct names, and the conditional really ought to evaluate as “true”. Also, I’ve tried many permutations of the conditional (negations, wrapping it in quotes and brackets and comparing to an empty string, etc) and had no real luck. The only version that sort of worked was this one:

    {description}
    {if "{description}"==''}{event_summary}
    {/if}

    But today I discovered that this code causes some of the entries to display a blank white page, so it looks like it’s not a very good solution after all.

    The “description” field is an LG TinyMCE, and event_summary is a Textarea. I’m using EE 1.6.8.

    Any ideas?

  • #2 / Aug 18, 2011 1:22am

    Boyink!

    5011 posts

    Try:

    {if description!=""}{description}
    {if:else}{event_summary}
    {/if}
  • #3 / Aug 18, 2011 2:53am

    John Henry Donovan

    12339 posts

    Hi Spurlock,

    Let us know if Mikes syntax works for you

  • #4 / Aug 18, 2011 9:39am

    Spurlock

    14 posts

    Hey guys,

    I’m going to tentatively say that it worked. All the entries that I was using to test the template (all of which had issues with at least one of the methods I tried) seem to render correctly with that code. Thanks!

    Any chance for a quick explanation why that syntax should work while the others should fail?

  • #5 / Aug 21, 2011 11:20pm

    Lisa Wess

    20502 posts

    Hi, Spurlock,

    {if blah}
    {/if}

    is considered a simple conditional.

    When you add an if:else or if:elseif it becomes an advanced conditional, and that changes how the parsing stages work. You can read about that in this wiki article on parse order.

    But what you ended up doing is mixing simple and advanced conditionals - it’s best to stick with one syntax so that you know what you are getting into.

    Make sense?

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

ExpressionEngine News!

#eecms, #events, #releases