Search Form Filter by Year Using entry_date
Hi,
I am trying to setup a search form which has an html select/option dropdown with a year filter. I read that whatever I am doing has to work with the start_on and stop_before parameters.
My code will look something like this:
<code>
<select name="">
<option value="">2012</option>
<option value="">2011</option>
<option value="">2010</option>
<option value="">2009</option>
</select>
The part that I do no understand is how to setup each option to work with both start_on and stop_before (in order for the two to cover exactly one calendar year). A code example of setting this up would be super helpful.
Thanks.
Replies
Low 9 Sep 2013 07:32
Just think of how you would get entries for a single year with the native channel:entries tag. You'd use the year="" parameter. You can use that parameter as an input field as well, just like any other parameter. So, you could simply use this:
Stoyan Vasilev 9 Sep 2013 18:25
Thank you! I did not realize the "year" parameter existed in the native tag. I should really read through the whole list of parameters.
The year filter works now and I have two other questions:
1) How do I preselect the year (in the years drodown) from the search query after the query is executed?
2) How do I preselect the collection (in the collections dropdown) from the search query after the query is executed?
My code looks like this: http://pastie.org/private/ravrubpjdl2...
Low 10 Sep 2013 07:51
You need to add the query-parameter to the Form tag, just like the Results tag.
Then you can use conditionals like this:
and this:
Also, since you're only letting the user choose a single collection, you can omit the square brackets in the <select> element name.
Stoyan Vasilev 10 Sep 2013 16:56
Hey,
I added the query parameter to the Form tag and removed the square brackets from the name attribute of the select element. The low_search_year value is outputted correctly and I implemented the year conditional statement successfully.
low_search_collection_id however does not render a value. Example, when I put this in my template:
I get this in the outputted markup:
What should I do?
Thanks.
Low 10 Sep 2013 16:59
Ah right, I should read my own documentation. :)
Check out the vars available in the {collections} var pair.
You can use {collection_is_active} var in your conditionals.
Also, you can leave out the show="not private_collection" bit, as that's just an example.
Stoyan Vasilev 10 Sep 2013 17:21
Kool. That did it. Thank you!