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.

conditional redirect

December 20, 2011 6:27am

Subscribe [4]
  • #1 / Dec 20, 2011 6:27am

    internetimages

    15 posts

    I have a loop of products that generate a list with link but, if the product is only one, must be redirect to a product page, instead of display the list.

    The code is:

    <ol>
      {exp:channel:entries channel="prod" category="{segment_3_category_id}"}
        {if total_results==1}
          {exp:hs_redirect location="/prod/view/{segment_3}/{url_title}"}
        {/if}
        <li>    
          <a href="/prod/view/{segment_3}/{url_title}">{descr_prod}</a>
        </li>
        {/exp:channel:entries}      
      </ol>

    But doesn’t work. It’s always redirect, seems that redirect is processed before {if}{/if} statement.

    I have tried also with EE {redirect} tag, without success.

    What’s wrong?

  • #2 / Dec 20, 2011 9:54am

    Design by Front

    106 posts

    Hi there,

    Have you tried using an embedded template to hold your redirect code? This might help with the parsing order. So your main template would have something like:

    <ol>
      {exp:channel:entries channel="prod" category="{segment_3_category_id}"}
        {if total_results==1}
          {embed=shared/_redirect location="/prod/view/{segment_3}/{url_title}"}
        {/if}
        <li>    
          <a href="/prod/view/{segment_3}/{url_title}">{descr_prod}</a>
        </li>
        {/exp:channel:entries}      
      </ol>

     

    And in your embedded template (shared/_redirect):

    {exp:hs_redirect location="{embed:location}"}

    As before, you should also try this with EE’s native redirect if the plugin doesn’t work

    Hope this helps,
    Chuck

  • #3 / Dec 21, 2011 11:06am

    Kevin Smith

    4784 posts

    internetimages, I think the fact that the redirect is being done by a plugin might be the problem here due to parse order. Have you tried this with the native redirect variable? Is there a reason you chose to go with the plugin instead?

  • #4 / Dec 21, 2011 11:38am

    internetimages

    15 posts

    internetimages, I think the fact that the redirect is being done by a plugin might be the problem here due to parse order. Have you tried this with the native redirect variable? Is there a reason you chose to go with the plugin instead?

    I’ve tried the plugin because with native redirect I got the wrong url:

    {redirect="/prod/view/{segment_3}/{url_title}"}

    send the browser to:

    <a href="http://site.com/prod/view/foo/{url_title">http://site.com/prod/view/foo/{url_title</a>

    The tag {url_title} is not parsed correctly…

    Now I’m going to try with embed.

  • #5 / Dec 21, 2011 11:48am

    internetimages

    15 posts

    Hi there,

    Have you tried using an embedded template to hold your redirect code? This might help with the parsing order. So your main template would have something like:

    Hope this helps,
    Chuck

    It works!! Thanks…

  • #6 / Dec 22, 2011 8:25pm

    Sean C. Smith

    3818 posts

    Internetimages,

    Glad to see you got it worked out. Feel free to post again when you need more assistance.

    Sean

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

ExpressionEngine News!

#eecms, #events, #releases