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.

Help needed refactoring a long conditional (EE bug?)

August 15, 2009 12:55pm

Subscribe [1]
  • #1 / Aug 15, 2009 12:55pm

    mikec964

    18 posts

    I’m trying to add a fairly complex conditional to my template, and the results are unpredictable. As best I can tell, if the conditional is too long, the entire {exp:weblog:entries} tag that contains it fails to execute.

    I pasted the conditional here, and added line feeds for readability. (It’s a shame I can’t have those line feeds in my actual source code.)

    As soon as I added the code between the >>> and <<<, the conditional stopped working.

    If there’s a way to refactor this or rewrite it in PHP, I’d really appreciate a hand. (I don’t know how to access EE variables in PHP, or I’d try that.)

    Thanks in advance!

    {exp:weblog:entries status="top menu|main menu|open" show_future_entries="yes" disable="categories|member_data|pagination|trackbacks|comments"}
    
    ... hello world! This line won't show if the conditional is too long.
    
    {if (>>>weblog_short_name!="board-minutes" AND <<<weblog_short_name!="board-only" AND weblog_short_name!="providers-only" AND weblog_short_name!="staff-only") 
    
    OR ((member_group==1 OR member_group==5 OR member_group==7)) 
    
    OR (>>>(weblog_short_name=="board-minutes" AND member_group==6)<<< 
    OR (weblog_short_name=="board-only" AND member_group==6) 
    OR (weblog_short_name=="providers-only" AND member_group==9) 
    OR (weblog_short_name=="staff-only" AND member_group==8))}
    
    ... show body text of page
    
    {if:else}
    ... not logged in or unauthorized
    {/if}
    
    {/exp:weblog:entries}

    [Mod Edit: Moved to the Technical Support forum]

  • #2 / Aug 15, 2009 1:13pm

    mikec964

    18 posts

    I was going to try my hand at a PHP rewrite and I realized my template had PHP input processing on.

    When I disabled PHP processing, the conditional began working.

    My page has no PHP in it anyway, so I’m without any idea of why this was a problem.

  • #3 / Aug 15, 2009 4:56pm

    Greg Aker

    6022 posts

    So this was only borking on you when PHP was enabled in the template?  What if it’s set to output?

    -greg

  • #4 / Aug 15, 2009 10:56pm

    mikec964

    18 posts

    Ugh. It broke again.

    I PHP on again and the template continued working. Then I changed PHP from output to input and it continued working. I turned PHP off and on and it continued working.

    I keep my templates under version control, so I thought I’d try an earlier version of the conditional to see if it’d work. The template broke.

    I used version control to roll back to the working template (I store them on the file system), and it still no longer worked. I turned PHP off and on, from input to output. I can’t get it to work anymore.

    Now I’m baffled again AND my page is broken.

  • #5 / Aug 16, 2009 10:19am

    mikec964

    18 posts

    Should I open another thread to report the EE bug that prevents it from processing long conditionals? And keep this one open for refactoring my code as a work-around, or rewriting it in PHP?

  • #6 / Aug 16, 2009 10:50am

    mikec964

    18 posts

    Why does adding three lines of PHP cause the entire {exp:weblog:entries} section to not display?

    This is my first PHP script, so I’m sure it’s something obvious.

    Here are the three lines that broke the script:

    if ($tGroup == 1) {
        echo "Still okay."
    }

    I have PHP parsing on output.

    Here’s the working code:

    <?php
    // must parse on output for $tWeblog to be assigned correctly
    echo "\n<!-- \n";
    $tApproval = false;
    
    $tWeblog = "{weblog_short_name}";
    echo "This weblog is $tWeblog. ";
    if ($tWeblog == "course") { echo "Is course.\n"; }
    if ($tWeblog != "board-minutes" AND $tWeblog != "board-only" AND $tWeblog != "providers-only" AND $tWeblog != "staff-only") { 
        $tApproval = true; 
        echo "Approved (not a private page). \n";
    }
    
    global $SESS;
    $tGroup = $SESS->userdata['group_id'];
    echo "The member group is $tGroup. ";
    if ($tGroup == 1 or $tGroup == 5 or $tGroup == 7) {
        $tApproval = true;
        echo "Approved (in a privileged group). \n";
    }
    
    echo "Final approval is $tApproval. ";
    echo "\n-->\n";
    ?>

    Here’s the non-working code:

    <?php
    // must parse on output for $tWeblog to be assigned correctly
    echo "\n<!-- \n";
    $tApproval = false;
    
    $tWeblog = "{weblog_short_name}";
    echo "This weblog is $tWeblog. ";
    if ($tWeblog == "course") { echo "Is course.\n"; }
    if ($tWeblog != "board-minutes" AND $tWeblog != "board-only" AND $tWeblog != "providers-only" AND $tWeblog != "staff-only") { 
        $tApproval = true; 
        echo "Approved (not a private page). \n";
    }
    
    global $SESS;
    $tGroup = $SESS->userdata['group_id'];
    echo "The member group is $tGroup. ";
    if ($tGroup == 1 or $tGroup == 5 or $tGroup == 7) {
        $tApproval = true;
        echo "Approved (in a privileged group). \n";
    }
    
    if ($tGroup == 1) {
        echo "Still okay."
    }
    
    echo "Final approval is $tApproval. ";
    echo "\n-->\n";
    ?>
  • #7 / Aug 16, 2009 1:50pm

    Greg Aker

    6022 posts

    How is it not working?  Do you have a link to where that is going on?

    ETA:  What version and build of ExpressionEngine are you running?  Do you have any extensions installed?

  • #8 / Aug 16, 2009 3:23pm

    mikec964

    18 posts

    When I add those three lines of PHP, then the outer {exp:weblog:entries} “fails” and nothing enclosed within it is displayed.

    This is similar to the failure mode when the EE advanced conditional was too long; it causes the enclosing :entries to evaluate to blank.

    I’m running EE 1.6.7.
    Modules: Freeform, Structure
    Extensions: LG Tiny MCE, LG Addon updater, Gypsy, File, Checkbox, Sarge, Moxiecode Authentication

    http://www.acrefamily.org/dev/index.php/training/cpr/
    Use afcc/stage75 to get into the staging area. (There’s nothing private there.)

  • #9 / Aug 16, 2009 3:29pm

    Greg Aker

    6022 posts

    can I have you disable extensions with the green button at the top of Admin -> Utilities -> Extensions Manager so we can take them out of the equation for the time being.

    -greg

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

ExpressionEngine News!

#eecms, #events, #releases