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.

Egad, category_request hates me / PHP parse error. Please help.

August 27, 2007 8:10pm

Subscribe [2]
  • #1 / Aug 27, 2007 8:10pm

    oldgoldblack

    113 posts

    EDIT: This is a problem with the category_request conditional, not PHP.

    I’m stumped by this error:

    Parse error: syntax error, unexpected T_ENDIF in /public_html/sys/core/core.functions.php(635) : eval()'d code on line 179

    I think that the following code is the source of the problem:

    {if not_category_request}
    {exp:weblog:entries weblog="news" orderby="date" sort="desc" start_on="<?php
    $d=date("D");
    $h=date("H");
    $todayfivepm=mktime(17, 0, 0,(int)date('m'),(int)date('d'),(int)date('Y'));
    if ($d=="Thu"&&$h>=17)
    echo date('Y-m-d H:i',$todayfivepm);
    else
    echo date('Y-m-d H:i',strtotime('last Thursday 17:00:00'));
    ?>
    "}
    {/if}

    I started getting this when I added the not_category_request conditional. Without the conditional, it’s fine. I just don’t see anything wrong, so I need an extra set of eyes. See anything?

  • #2 / Aug 27, 2007 8:24pm

    maadmac

    224 posts

    I started getting this when I added the not_category_request conditional. Without the conditional, it’s fine. I just don’t see anything wrong, so I need an extra set of eyes. See anything?

    Hmm, try this:

    if ($d=="Thu"&&$h>=17) {
    echo date('Y-m-d H:i',$todayfivepm);
    } else {
    echo date('Y-m-d H:i',strtotime('last Thursday 17:00:00'));
    } 
    ?>
    "}
    {/if}

    Not sure if that’s it, but I know whenever I have multi-step PHP conditionals (that is, more than just “if this echo that”) I always include the curly braces… that’s usually what is meant by a T_ENDIF error.

  • #3 / Aug 27, 2007 8:55pm

    oldgoldblack

    113 posts

    I tried that and no luck. Though it did change the line of the error report.

  • #4 / Aug 27, 2007 9:24pm

    oldgoldblack

    113 posts

    It looks like my one section of PHP is not the problem, but the category_request conditional is. Even when I replace the fancy PHP “give me the date I want” code with a handwritten date, it still give me the same error.  Take the conditional out, the page loads as I would expect.

    Is there something about the use of this conditional I don’t know? Parsing order problem maybe? Here’s a larger snippet of the code in question…

    {exp:weblog:category_heading}
    News topic: {category_name}
    {/exp:weblog:category_heading}

    {if not_category_request}
    {exp:weblog:entries weblog="news" orderby="date" sort="desc" start_on="2007-08-23 17:00 PM"}
    {/if}

    {if category_request}
    {exp:weblog:entries weblog="news" orderby="date" sort="desc"}
    {/if}

    blah blah blah

    {/exp:weblog:entries}

    FYI, I’m not using the category name URL thingamajig. It’s /C#.

    So I guess this belongs in tech support, not a design. This has not been a good week for me. :shut:  Everything I’ve tried to do to EE since Thursday has been an unanticipated disaster. Just by the law of large numbers, something has to work eventually, right? Right?

  • #5 / Aug 28, 2007 11:02am

    silenz

    1651 posts

    These conditionals only work inside a pair of {exp:weblog:entries}-tags.

    What happens internally in the parsing routine when you do this

    {if not_category_request}
    {exp:weblog:entries weblog="news" orderby="date" sort="desc" start_on="2007-08-23 17:00 PM"}
    {/if}
    blah blah blah
    {/exp:weblog:entries}

    is that the closing {/if}-statement is repeated once per weblog-entry. This results in one open {if}-statement and numerous closing {/if}-statements which ulimatively leads to the PHP-error.

    Now how do you achieve what you want?
    At a glance a possible solution would be:

    {exp:weblog:entries limit="1"}
    
    {if not_category_request}
    {embed=site/not_categ}
    {/if}
    
    {if category_request}
    {embed=site/categ}
    {/if}
    
    {/exp:weblog:entries}

    Template site/categ would contain:

    {exp:weblog:entries weblog="news" orderby="date" sort="desc"}
    
    blah blah blah
    
    {/exp:weblog:entries}

    Template site/not_categ would contain:

    {exp:weblog:entries weblog="news" orderby="date" sort="desc" start_on="2007-08-23 17:00 PM"} 
    
    blah blah blah
    
    {/exp:weblog:entries}

    Not elegant but should work as intended. Perhaps someone can come up with a neater solution.

  • #6 / Aug 28, 2007 4:47pm

    oldgoldblack

    113 posts

    Ah, yes, that should have been fairly obvious, shouldn’t it? Thanks! Your solution looks good enough to me. I’ll try it out.

  • #7 / Aug 28, 2007 9:40pm

    oldgoldblack

    113 posts

    That did not work at all. Taking the if out of the loop did indeed solve the parse error, but I still could not get the results I wanted. After hours of working on it, I tried to put nothing but text within the category_request conditionals. Nothing showed up on the page at all. So, at this point I gave up. I believe I had the syntax correct (I checked many many times), but still no luck.

    So I just used another template just to change one line of code. Oh well. If there’s something I did wrong, I’d still like to know what it is.

  • #8 / Aug 29, 2007 6:11am

    silenz

    1651 posts

    I tried to put nothing but text within the category_request conditionals. Nothing showed up on the page at all.

    Let’s reduce it as much as possible.

    Does this work?

    {exp:weblog:entries limit="1"}
    {if not_category_request}
    This is not a cetagory request.
    {/if}
    {/exp:weblog:entries}
.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases