All Low add-ons are now owned by EEHarbor. Read the blog post.

Support archive

Selecting collection on search tag

notoriouswebmaster 24 Apr 2013 21:23 question, complete

Depending on a cookie value, I'd like to select the collection to draw my results from. So I have this code:

{exp:low_search:results query="{segment_3}"
collection="{if '{cookie}' == 'product'}products{if:else}blog{/if}"
status="open|{if '{cookie}' == 'product'}wide{if:else}featured{/if}"
}

But it's always coming up with a collection of products. Any ideas?

Replies

  1. Low 24 Apr 2013 21:32

    That's a parse order issue. The conditionals are advanced, and therefore parsed after tags. So when the tags are parsed, the parameter value contains the literal code.

    To circumvent, install Mo Variables to get access to early parsed vars, including cookie vars.

    Once installed, use simple conditionals only. You can use that in combination with preload replace vars for the parameters:

    {if cookie:my_cookie == 'product'} 
    {preload_replace:pre_collection="products"}
    {preload_replace:pre_status="wide"}
    {/if}
    {preload_replace:pre_collection="blog"}
    {preload_replace:pre_status="featured"}


    That's the logic to get the correct parameter values. Note that I'm not using {if:else}. The cookie:my_cookie vars should be available through Mo Variables.

    Then, use this opening tag for the Results tag:

    {exp:low_search:results query="{segment_3}" 
    collection="{pre_collection}"
    status="open|{pre_status}"
    }

    notoriouswebmaster 24 Apr 2013 21:57

    Thx Low. I'll tackle this in the morning. I may have some questions. Still unsure about advanced conditionals. Have a good evening.

    notoriouswebmaster 25 Apr 2013 15:17

    OK understand simple and advanced conditionals now. Can you walk me through why {pre_collection} won't always be 'blog'? (And I already had Mo Variables installed. So we're good to go.)

    notoriouswebmaster 25 Apr 2013 15:23

    Oh, I think I get it. The conditional is run after the stuff outside of the conditional. This is why EE makes me crazy. Is there some good article out there on how parse order works? I've looked at the ellislab docs and they don't explain it very well.

    Low 26 Apr 2013 07:46

    Check out this answer on EE-Answers: http://expressionengine.stackexchange...
    It contains several links to parse order resources.