How do you loop through past items in a search in a Zotonic template?
I would like to able to loop through past events in a template:
{% for page in m.search[{past cat='event'}] %}
{% if forloop.first %}<ul>{% endif %}
<h2>{{ m.rsc[page].date_start|date:"M j, Y" }} {{ m.rsc[page].title }}</h2>
<p>{{ m.rsc[page].body|show_media }}</p>
<p><a href="{{ m.rsc[page].website }}">Register to attend this event.</a></p>
{% i开发者_如何学Cf forloop.last %}</ul>{% endif %}
{% endfor %}
Basically I am looking for a past search type that acts as the opposite of the upcoming search type.
I already can get upcoming events as follows:
{% for page in m.search[{upcoming cat='event'}] %}
{% if forloop.first %}<ul>{% endif %}
<h2>{{ m.rsc[page].date_start|date:"M j, Y" }} {{ m.rsc[page].title }}</h2>
<p>{{ m.rsc[page].body|show_media }}</p>
<p><a href="{{ m.rsc[page].website }}">Register to attend this event.</a></p>
{% if forloop.last %}</ul>{% endif %}
{% endfor %}
I have no qualms coding this if I am pointed in the right direction and I will contribute the result back to the master code base.
How do you loop through past items in a search in a Zotonic template?
You could use the date_start_before
term of the Query search model, which is apparently undocumented, though I did find it looking at the source code in search_query.erl (line 293).
Though I think your query should check the pivot_date_end and not the pivot_date_start.
To make this more accessible you could add a handler (much like upcoming
) to the mod_search.erl module, eventually also modifying
The mod_search module implements most searches.
See also http://zotonic.com/documentation/761/the-query-search-model
Patches are welcome :-)
精彩评论