Beginner questions - displaying results on same page and query segments
Hi Low community! I have some beginner questions that I couldn't quite answer by looking through the docs. First, is regarding query segments. How do I know which segment to use? Secondly, I have the search in the side bar of a page. I want users to first see unfiltered entries in a channel when they visit the page, but if they submit, I want the filtered search results to appear instead. Do people typically create two templates for this purpose, or use conditionals in some way?
Thank you!
Replies
Low 16 Jan 2015 17:43
You can choose which segment to use, based on the result_page parameter. By default, the encoded hash will be appended to the result_page, but you can use %s to place it anywhere.
So, result_page="search" will result in a URL like domain.com/search/HASH so you use {segment_2} in query="{segment_2}".
You can use the Results page as a replacement for the channel:entries tag. Say you do this in the search/index template, so the url domain.com/search contains the Results tag. If you add query="{segment_2}" to it, and segment_2 is empty, it won't filter based on the queries, but rather show all entries instead. If you search, the hash will get added to the URL, and therefore the tag will then filter results by that query.
Make sense?
Patricia Vaccaro-Coburn 16 Jan 2015 17:48
Yes, thank you so much! You're the best.