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.

Conditionals not working still!

September 01, 2012 7:12am

Subscribe [3]
  • #1 / Sep 01, 2012 7:12am

    leeaston

    634 posts

    Latest EE.

    I’m confused by if conditionals. For example how would I test if entry_date equals current_time using the 2 tags below?

    {entry_date format='%Y%m%d'} {current_time format='%Y%m%d'}

    Normally I’d do

    {if "{entry_date format='%Y%m%d'}" ==  "{current_time format='%Y%m%d'}"}Today{/if}

    but that dosen’t work - please try it yourself and let me know what happens.

    There have been other reports and bug fixes for this type of problem:
    http://ellislab.com/forums/viewthread/218563/
    https://support.ellislab.com/bugs/detail/17989 (2 fixes posted)
    http://ellislab.com/forums/viewthread/223416/ (with a different fix to those above)

    I’d like to know what the real fix is that gets my conditional above working please?

    Best wishes
    Lee

  • #2 / Sep 04, 2012 7:56pm

    Kevin Smith

    4784 posts

    Hi Lee,

    Thanks for posting. Even the fixes that are coming in the next release applied, here’s the error I’m getting when I use the conditional you posted:

    A PHP Error was encountered
    
    Severity: User Warning
    
    Message: Invalid EE Conditional Variable: {if "{"1336576871" format='%Y%m%d'}
    
    Filename: libraries/Functions.php
    
    Line Number: 2863
    A PHP Error was encountered
    
    Severity: User Warning
    
    Message: Invalid EE Conditional Variable: {if "{"1336576870" format='%Y%m%d'}
    
    Filename: libraries/Functions.php
    
    Line Number: 2863

    I’m going to grab one of the engineers to see what they can make of this. Hang on for me!

  • #3 / Sep 05, 2012 5:22am

    Steven Grant

    894 posts

    get rid of the format tag, not really needed for this kind of logic because

    {if entry_date ==  current_time}Today{/if}

    is the same.

  • #4 / Sep 05, 2012 5:50am

    leeaston

    634 posts

    It is needed. Your tag will never output anything unless entry_date is the exact same time (to the second) as current_time.

  • #5 / Sep 05, 2012 5:54am

    Steven Grant

    894 posts

    ah good point, didn’t think of it like that.

  • #6 / Sep 05, 2012 4:21pm

    Kevin Smith

    4784 posts

    Lee, could you provide some more context for the template? Could you pare your template down to the minimum where you still get errors and post that here so we can test against that?

  • #7 / Sep 05, 2012 4:56pm

    leeaston

    634 posts

    Not exactly my template, but simple and givers errors.

    {exp:channel:entries channel="my_channel"}
    
    {title} {if "{entry_date format='%Y%m%d'}" ==  "{current_time format='%Y%m%d'}"}Today{/if}<br><br>
    
    {/exp:channel:entries}

    Gives:

    A PHP Error was encountered
    
    Severity: User Warning
    
    Message: Invalid EE Conditional Variable: {if "{entry_date format="%Y%m%d"}
    
    Filename: libraries/Functions.php
    
    Line Number: 2843
    A PHP Error was encountered
    
    Severity: Warning
    
    Message: Cannot modify header information - headers already sent by (output started at /data/sites/web/www/system/codeigniter/system/core/Exceptions.php:170)
    
    Filename: core/Common.php
    
    Line Number: 408
  • #8 / Sep 05, 2012 5:15pm

    Kevin Smith

    4784 posts

    Hey Lee,

    I just had one of the engineers take a look at your example, and he reported back that he gets errors running it in EE 2.5.2, just like you see here, but that the conditional works as expected in the codebase for the next release. The solution involves more than just a few lines of code changed, so I can’t share it, but it will be in the next release.

  • #9 / Sep 05, 2012 5:24pm

    leeaston

    634 posts

    As you’re not going to tell me when the next release is and I need this to work on my site, can you please email me the updated files so I can get on? Plus others are waiting on the fix :https://support.ellislab.com/bugs/detail/17989

  • #10 / Sep 06, 2012 3:58pm

    Kevin Smith

    4784 posts

    I’m afraid that’s not possible. The changes in the next release involve lines and files that aren’t all necessarily related to this particular issue, so there’s no way to merely send you the changes that are only meant to fix this issue. But I can assure you that we want to make sure you get this issue resolved as soon as possible!

  • #11 / Sep 06, 2012 4:26pm

    leeaston

    634 posts

    But I can assure you that we want to make sure you get this issue resolved as soon as possible!

    No you’re not - you just think you are.

  • #12 / Sep 07, 2012 4:05pm

    Kevin Smith

    4784 posts

    I really hate that you feel that way, Lee. I guess there’s not much more I can offer. The changes made to fix this issue involve multiple lines in multiple files that also have other changes to fix other bugs. It just wouldn’t be smart to pull those files out of the next release and send them to anyone. It wouldn’t help fix the problem since it would result in a big version mismatch problem. You’d inevitably run into even more issues.

  • #13 / Sep 07, 2012 5:37pm

    leeaston

    634 posts

    Let me recap. So something (conditionals) that has been working ok for years is reprogrammed by your engineers not to work anymore. I spend many hours confirming my suspicions and post my findings on the forum. In the mean time I can’t launch my site because basic functionality is not working as advertised. And then you tell me we fixed it, but hey guess what, you can’t have the fix, we can’t tell you when you can have the fix and we really hate that you feel that you think we’ve let you down. Yeah right…

    Anyway enough is enough - please do not reply and close this thread.

  • #14 / Sep 10, 2012 5:24pm

    Kevin Smith

    4784 posts

    Hey Lee,

    As I’m sure you understand, conditionals can be a very complicated thing, and our engineers have just been taking the prudent steps to make sure that this upcoming release fixes the several issues surrounding conditionals without introducing new bugs to the mix. When a bug or set of bugs is as complicated as these were, it simply takes a lot of time to diagnose the problem, fix it, and test the fixes. You were a big part of helping us there, and I want to thank you for that.

    Believe me, I understand it’s frustrating not to be able to launch the site. And I understand why you’re pissed about it. That’s ok. Even if you don’t feel like talking, I hope you know that we’re here, and we really truly do want to help.

  • #15 / Sep 11, 2012 2:55pm

    Kevin Smith

    4784 posts

    Hey Lee,

    Just reactivating this post to update you: I wanted to make sure you heard about the 2.5.3 release today, which contains all those bug fixes I was talking about. As you can see, there were just a slew of bug fixes in this release. Probably our biggest stability release yet.

    Let me recommend updating to 2.5.3 and then applying this additional change. Find line 2779 in Functions.php. It should look like this:

    $matches[3] = str_replace(array_keys($protect), array_values($protect), $matches[3]);

    And replace it with this:

    // Example:
    // 
    //     {if entry_date < current_time}FUTURE{/if}
    //     {if "{entry_date format='%Y%m%d'}" ==  "{current_time format='%Y%m%d'}"}Today{/if}
    // 
    // The above used to fail because the second conditional would turn into something like:
    // 
    //     {if "{"1343930801" format='%Y%m%d'}
    //
    // So here, we make sure the value we're replacing doesn't ALSO happen to appear in the
    // middle of something that looks like a date field with a format parameter
    foreach ($matches[3] as &$match)
    {
      foreach ($protect as $key => $value)
      {
        // Make sure $key doesn't appear as "{$key "
        if ( ! strstr($match, LD.$key.' '))
        {
          $match = str_replace($key, $value, $match);
        }
      }
    }

    Our engineers crafted it after the 2.5.3 release went into code freeze, so it didn’t make it in, but it should take care of any remaining issues you have. There were several changes that took care of several different aspects of the conditionals issues folks were having, and this one additional code change should wrap it all up. Let me know if there are still any weird issues after the update to EE 2.5.3 + the above code change.

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

ExpressionEngine News!

#eecms, #events, #releases