Low Search form & results on one page
Hi Low
Ok, I use a bunch of your addons with much success but I am a little stuck with Low Search.
I am trying to create a page at /search which when loaded without a query string will load the advanced search form (I have a simple search on every page working well!), but when loaded with a query will return search results.
so:
/search -> empty advanced search form
/search?keywords=bamboo -> a results set for this search
I can't seem to get it it work. Low Search just seems to want to return results no matter what if there is a a results tag on the page. If I create a tiny test template with nothing but:
[code]
{exp:low_search:results parse="inward" parse="inward" }
{if low_search_no_results}
{exp:low_search:form search_mode="all" }
Search
{/exp:low_search:form}
{/if}
{entry_id}
{/exp:low_search:results}
[/code]
...it will print out all entry_ids.
Conceptually I imagine that is happening as I am not doing any filtering, so it makes sense - but I am just being dumb here and can't see how I can filter when there is not form sending any filters, if you see what I mean.
I am sure the answer is obvious - could you point me in the right direction please?
Van harte bedankt, je hebt echt goed Addons ge-coded, apologies for the pidgeon Dutch, many years since I lived over there now!,
Jeremy
Replies
Low 25 Feb 2014 08:33
I wouldn't nest the Results and Form tags like that. Using the non-encoded query option, the Results tag will just return unfiltered results when there is no query string present.
Instead, you might want to use a conditional to check for it. The {current_query_string} var looks like it's up for the job. I checked, and it should be an early parsed var, too. That means you should be able to use something like this:
Jeremy Daalder 25 Feb 2014 08:47
Wow - that was fast. Aren't you in bed over there?? Thanks so much!
Yep that appears to work.
Ok, now to add some stash magic etc.
Is there a good discussion somewhere of the pros/cons of encoded/non-encoded? I like the neat urls of non-encoded but if there are significant negatives to it I'd happily go the other way
Low 25 Feb 2014 09:24
Nope, just started work here. :)
I don't know if there's a discussion somewhere, but I'll give you my 2 cents:
Personally, I prefer the encoded queries, so I can use segment vars to do logic. But having the current_query_string there might help too. It's just that using GET vars isn't always supported on each install. Instead, the encoded queries will always work.
But in the end, it's a matter of personal preference.