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

Support archive

Low Search channel snippet

Robert M 2 Oct 2014 00:31 question, complete

My search result should only display channel entries based on users user group.

{exp:low_search:results
query="{segment_2}"
status="not closed"
disable="member_data|category_fields"
channel="{if snip_productx ~ '/\b'.logged_in_member_group.'\b/'}channelx{/if}"
}

In snippet 'snip_bookx' I have member group IDs.

I've used this system on the EE site for users to have access to specific channels, but for Low Search this system does not work. I've tried to put the code with snippet in another template an embed it without success.

Replies

  1. Low 2 Oct 2014 08:37

    It's probably a parse order issue: the conditional isn't parsed yet when the tags are parsed. What happens if you turn on Template Debugging and look up the actual opening low_search:results tag? What does that say?

  2. Robert M 2 Oct 2014 22:48

    Hi,

    Template debugging result:

    (0.022454 / 3.54MB) Tag: {exp:low_search:results query="eyJyZXN1bHRfcGFnZSI6InRlc3QiLCJrZXl3b3JkcyI6InNhbWUifQ" status="not closed" disable="member_data|category_fields" channel="{!-- ra:000000002fe4235700000000b4370ace --}{if '1' ~ '/\b' . logged_in_member_group . '\b/'}channelx{/if}" }

    It looks like the snippet parse, but I discovered sneaky little code turns up:
    {!-- ra:000000002fe4235700000000b4370ace --}

    I'm on EE Version 2.9, and I have discovered this code on few other modules (FireMail and Solspace Forms - fixed now by updated modules) after we upgraded to EE2.9

  3. Low 3 Oct 2014 06:52

    Instead of using a conditional in the parameter like that, I'd try using preload replace vars instead:

    {if snip_productx ~ '/\b'.logged_in_member_group.'\b/'}
    {preload_replace:pre_channel="channelx"}
    {/if}
    {preload_replace:pre_channel=""}
    {exp:low_search:results channel="{pre_channel}" ... }
    Does that help?

  4. Robert M 7 Oct 2014 01:04

    Hi,

    The snippet should not display channel in exp:low_search:results

    The snippet content: 5, so super admin (ID: 1) should not display

    Template:

    {if snip_book_test ~ '/\b'.logged_in_member_group.'\b/'}
    {preload_replace:pre_channel="tsbtb"}
    {/if}

    {exp:low_search:results
    query="{segment_2}"
    status="not closed"
    disable="member_data|category_fields"
    channel="{pre_channel}"
    }

    ----

    Debugger result:

    (0.006191 / 3.25MB) Snippets (Keys): freelancer_version|snip_book_psalms|snip_book_cross|snip_book_test|snip_book_mistaken-identity|snip_book_fyw|snip_book_resurrection|snip_book_sneaking|snip_book_tsbtb|snip_book_war|site_id|site_label|site_short_name|last_segment|current_url|current_path|current_query_string|is_core
    (0.006217 / 3.25MB) Snippets (Values): FALSE|1|1|5|1,10,18,17,15,14,24,29,31,32,34,8,38,39,40,45,51,52,53,56,57,63,66,10,18,17,15,14,24,29,31,32,34,8,38,39,40,45,51,52,53,56,57,63,21,71, 7|1,6,7,18,27,28,32,33,38,43,47,50,54,69,66,10,18,17,15,14,24,29,31,32,34,8,38,39,40,45,51,52,53,56,57,63,21|1,21,64|1,21,29,35,40,45,48,52,54,57,59,61,68,71|1,42,71,21|1,15,45,68,7|1|CEP Teachers Lounge|default_site|eyJyZXN1bHRfcGFnZSI6InRlc3QiLCJrZXl3b3JkcyI6InNleCJ9|http://domainname/test/eyJyZXN1bHRfcG...||
    (0.006681 / 3.26MB) Parse Date Format String Constants
    (0.006700 / 3.26MB) Parse Current Time Variables
    (0.006843 / 3.26MB) Parsing Segment, Embed, Layout, logged_in_*, and Global Vars Conditionals
    (0.017999 / 3.53MB) Processing Preload Text Replacements: pre_channel
    (0.020830 / 3.54MB) - Beginning Tag Processing -
    (0.020856 / 3.54MB) Parsing Tags in Template
    (0.020892 / 3.54MB) Tag: {exp:low_search:form result_page="test"}
    (0.020997 / 3.54MB) Closing Tag Found
    (0.021070 / 3.55MB) Tag: {exp:low_search:results query="eyJyZXN1bHRfcGFnZSI6InRlc3QiLCJrZXl3b3JkcyI6InNleCJ9" status="not closed" disable="member_data|category_fields" channel="tsbtb" }

  5. Low 7 Oct 2014 13:22

    It's probably because the {logged_in_group_id} var is not available as an early parsed var. Try installing Mo Variables to change that.

  6. Robert M 8 Oct 2014 22:22

    Excellent, thanks for your tips, it all working 100%