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

Support archive

Pass collection from {low_search:form} to results template

NIall O'Brien 16 Jan 2015 11:45 question, complete

Hi, I have a low_search:form tag that uses a drop down for the user to select the collection they want to search. In the results template, I have "blocks" for each collection to list the results eg. {exp:low_search:results query="{segment_3}" collection="news"}...{/exp:low_search:form}

{exp:low_search:results query="{segment_3}" collection="documents"}...{/exp:low_search:form}

Of course, the results page will find results for each "block" - how can I access the collection they would have selected in the previous form?

For the record, I open a select tag, then loop through collection for each option tag.

Thanks in advance.

Replies

  1. Low 16 Jan 2015 12:20

    In your examples you're using a different opening and closing tag:

    {exp:low_search:results} ... {/exp:low_search:form}

    I take it you mean the Form tag in both cases.

    The Form tag doesn't accept any filter-parameters. Instead, use an (hidden) input field if you want to make the parameter dynamic, or hard-code it in the Results tag.

  2. NIall O'Brien 16 Jan 2015 12:26

    Apologies.

    No, in my results template I'm using multiple low_search:results tags for each collection, but really only want the results page to show the results of searching one specific collection. However, my current approach will find the keywords in every collection listed on the results page. Ideally I want to get the collection that was selected when the user posted the form and use this within my results template to limit the collections to be searched.

    Thanks.

  3. Low 16 Jan 2015 12:31

    Couldn't you just replace all the Results tags with one single Results tag, and not specify the collection-parameter? Then you'll only get results from the selected collection in the form.

  4. NIall O'Brien 16 Jan 2015 12:38

    I would if it were that easy, however the presentation of certain results for collections are completely different; many different types of media. Eg. videos, photos, PDF previews etc. Any suggestions? Thanks.

  5. Low 16 Jan 2015 12:41

    You could use conditionals to check for channel / collection and apply the right formatting like that. It would be better for performance as well:

    {if channel_short_name == 'videos'} 
    ...videos entry...
    {if:elseif channel_short_name == 'photos'}
    ...photos entry...
    {if:elseif channel_short_name == 'foo'}
    ...foo entry...
    {if:else}
    ...general entries...
    {/if}

  6. NIall O'Brien 16 Jan 2015 12:47

    You're right, it'd certainly reduce the queries. Thanks for the suggestion, I shall try that and let you know how it works out.

    Thanks again.

  7. NIall O'Brien 16 Jan 2015 14:05

    Seems that it still outputs results from all of the collections. :(

  8. Low 16 Jan 2015 14:06

    What's your Form and Results template code? You can use http://pastie.org/ or http://pastebin.com/ for large chunks of code.

  9. NIall O'Brien 16 Jan 2015 14:15

    Form: http://pastebin.com/zVRA8fER
    Results: http://pastebin.com/tfpruxQN

    Thanks in advance.

  10. Low 16 Jan 2015 14:25

    On line #13 of your Form, the name attribute of the <select> should be name="collection" instead of name="media_type".

    You can remove the name attribute from the <option> tags. That doesn't do anything.

  11. NIall O'Brien 16 Jan 2015 14:31

    Thank you, well spotted. That worked perfectly. :)