views:

13

answers:

1

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>
    {% if 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?

+1  A: 

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 :-)

Marc W
date_start_before needs an argument. I used m.search[{query cat='event' sort="rsc.pivot_date_start" date_start_before=now}]
Alain O'Dea
Oddly it looks like upcoming does not work for me. It might be that I don't have date_end set on my events.
Alain O'Dea
I can't understand why upcoming doesn't work because it looks to be equivalent to "date_start_after=now", but somehow operates differently.
Alain O'Dea
Actually it checks for the pivoted date: pivot_date_start This date is a normalized (and indexed) version of date_start.
Marc W