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.

PHP Output with EE Conditionals not working properly

December 07, 2012 2:15pm

Subscribe [0]
  • #1 / Dec 07, 2012 2:15pm

    ultra16

    9 posts

    I’m stumped. I’ve been using EE for years but this problem has got me running around in circles.

    It’s simple, just set a template to PHP enabled and OUTPUT and then add this code in:

    <?php $seg1 = TRUE; ?>
    
    {if "{segment_1}" == "doggy"}
    <?php 
    $seg1 = FALSE; 
    echo 'DOGGY'; 
    ?>
    {/if}
    
    <?php echo ($seg1) ? "Seg1 is TRUE" : "Seg1 is FALSE"; ?>

    Ok, so we have a SIMPLE CONDITIONAL which should parse before PHP. Go to a the page, and make sure segment_1 doesn’t have doggy in it. You’ll notice that “DOGGY” doesn’t print out, which is expected! But then you’ll see that “Seg1 is FALSE” is echoed out!

    This doesn’t make any sense to me. Why is the PHP code that sets $seg1 to false being executed when it isn’t supposed to AND when the echo statement isn’t being executed?

    Can anyone else reproduce this? I’m using version 2.5.3.

    (p.s. really annoyed with EE not having the tech support section anyone, but hopefully the community is as good as it used to be)

     

  • #2 / Dec 07, 2012 2:19pm

    ultra16

    9 posts

    Bah! Nevermind, it seems my conditional should be:

    {if segment_1 == "doggy"}

    Not sure why I didn’t see that.

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

ExpressionEngine News!

#eecms, #events, #releases