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.

Redirect tag is parsing first?

May 24, 2011 7:17am

Subscribe [3]
  • #1 / May 24, 2011 7:17am

    Ian Ebden

    312 posts

    Here’s a little dilemma I’ve got. I’m hoping to use 1 template to handle both section and subsection pages. For example, if my URL is:

    http://address.com/template_group

    ...I want to display the section content. However, if the URL is:

    http://address.com/template_group/url_title

    ...I want to display subsection (page) content.

    I was hoping to do something like this:

    {if segment_2}{!-- display a subsection page --}
    {exp:channel:entries 
        channel="mychannel" 
        disable="categories|member_data|pagination" 
        dynamic="yes" 
        limit="1" 
        require_entry="yes"
    }
    {if no_results}{redirect='error'}{/if}
    {title} etc…
    {/exp:channel:entries}
    
    {if:else} {!-- display section page --}
    {exp:channel:entries 
        channel="mychannel" 
        disable="categories|member_data|pagination" 
        dynamic="no" 
        limit="1" 
    }
    {title} etc…
    {/exp:channel:entries}
    {/if}

    However for some reason the {redirect} tag is kicking in when I try the URL http://address.com/template_group and I don’t get my section page. Any ideas?

    Thnx

  • #2 / May 24, 2011 3:27pm

    Brandon Jones

    5500 posts

    Hi Ian,

    Take a look at this thread - essentially it’s a parse order issue. You might try using simple conditionals (if instead of if:else) or embeds in this case.

  • #3 / May 24, 2011 3:42pm

    Ian Ebden

    312 posts

    Makes sense, thanks Brandon. Simple conditions doesn’t help and I’d rather not use embeds. Hmm… Back to the drawing board.

  • #4 / May 25, 2011 5:34am

    Ian Ebden

    312 posts

    For future reference, after some twiddling I got this working:

    {if segment_2==""}{!-- display section page --}
    {exp:channel:entries 
        channel="mychannel" 
        disable="categories|member_data|pagination" 
        dynamic="no" 
        limit="1" 
        sort="asc"
    }
    {/if}
    
    {if segment_2}{!-- display a subsection page --}
    {exp:channel:entries 
        channel="mychannel" 
        disable="categories|member_data|pagination" 
        dynamic="yes" 
        limit="1" 
        require_entry="yes"
    }
    {if no_results}{redirect='error'}{/if}
    {/if}
    ... rest of page code here…
  • #5 / May 26, 2011 10:26am

    Sue Crocker

    26054 posts

    Thanks for posting your solution, I’m sure it will help others who have similar problems. If anything else comes up, please do let us know in a new thread..

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

ExpressionEngine News!

#eecms, #events, #releases