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.

Strange behavior of conditional with {redirect} inside

December 23, 2009 1:02pm

Subscribe [4]
  • #1 / Dec 23, 2009 1:02pm

    Georgiy Ivankin

    7 posts

    I have the following code in the template:

    {if segment_2!='' AND segment_2!='category'}
        {exp:weblog:entries weblog="tariffs" require_entry="yes" disable="member_data|pagination|trackback" limit="1"}
            {if no_results}
                {redirect="404"}
            {/if}
            <h1>{title}</h1>
            {page_body}
        {/exp:weblog:entries}
    {/if}
    
    {if segment_2=='category'}
    Blah
    {/if}

    As far as I’m concerned, one should see that “Blah” on http://my-site.com/index.php/tariffs/category/some_category_name, because the first conditional is totally ignored. However, I get a 404. But! If I replace {redirect="404"} with anything else, say “foo”, I see that “Blah” — everything works as expected.

    Thanks in advance for your support.

  • #2 / Dec 23, 2009 3:39pm

    Sue Crocker

    26054 posts

    Can you try adding a space between segment_2 and the ! character? Same thing with segment_3.

  • #3 / Dec 25, 2009 4:25am

    Georgiy Ivankin

    7 posts

    Adding a space gave no results. And there is no “segment_3” in the code.

  • #4 / Dec 27, 2009 2:36pm

    Greg Salt

    3988 posts

    Hi Georgiy,

    When you say you got no results do you mean that the redirect worked and you got directed to your 404 page or that nothing was displayed on the template at all?

    Cheers

    Greg

  • #5 / Dec 28, 2009 4:26am

    Georgiy Ivankin

    7 posts

    Hi Greg,
    I mean that I still get a 404 redirect

  • #6 / Dec 28, 2009 6:07pm

    Ingmar

    29245 posts

    This looks like a parse order issue. Can you try nested (or embedded) Simple Conditionals? Try putting the whole {exp:weblog:entries} block into a sub template.

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

ExpressionEngine News!

#eecms, #events, #releases