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

Support archive

Low Search Result Conditional

Jemes 4 Nov 2014 13:26 question, complete

I'm having issues with the conditional below.

I only want to add default:category="{segment_3_category_id} when type-1 or type-3 are not in segment_3 of the url.

It works when I remove the OR type-3 line but adding extra OR logic breaks the tag..


{exp:low_search:results collection="product" {if segment_3 != "type-1" || segment_3 != "type-3"}default:category="{segment_3_category_id}"{/if}}

Replies

  1. Low 4 Nov 2014 14:22

    First of all, the logic in the IF statement will always return TRUE. If segment_3 is "type-1", the second half of the query is true. If it's "type-1", the first half is true. You'd need to combine the two halves with AND, not OR.

    Then, only when you're using EE 2.9+, the conditional will be parsed in time before parsing tags. But, in general, I recommend against using conditionals in opening tags anyway. Try using Preload Replace variables instead. Something like:

    {if segment_3 == "type-1"}
    {preload_replace:pre_cat=""}
    {/if}
    {if segment_3 == "type-3"}
    {preload_replace:pre_cat=""}
    {/if}
    {preload_replace:pre_cat="{segment_3_category_id}"}
    {exp:low_search:results ... default:category="{pre_cat}" ... }

  2. Jemes 4 Nov 2014 15:17

    The Preload Replace work great, thanks.