如何在Zotonic模板中搜索过去的项目?
问题描述:
我希望能够遍历模板往事:如何在Zotonic模板中搜索过去的项目?
{% 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 %}
基本上我寻找充当即将搜索类型的对面过去搜索类型。
我已经可以得到即将举行的活动如下:
{% 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 %}
我没有疑虑编码这一点,如果我指出了正确的方向,我将有助于将结果返回到主代码库。
如何在Zotonic模板中搜索过去的项目?
答
您可以使用查询搜索模型的date_start_before
条款,该条款显然没有记录,但我确实发现它查看search_query.erl(第293行)中的源代码。
虽然我认为你的查询应该检查pivot_date_end而不是pivot_date_start。
为了使这个更容易,你可以(很像upcoming
)添加处理程序到mod_search.erl模块,最终也改变
的mod_search模块实现了大部分的搜索。
参见http://zotonic.com/documentation/761/the-query-search-model
补丁,欢迎:-)
date_start_before需要一个自变量。我用m.search [{cat ='event'sort =“rsc.pivot_date_start”date_start_before = now}] – 2010-10-25 12:58:59
奇怪的是,它看起来像即将到来并不适合我。这可能是因为我没有在我的活动中设置date_end。 – 2010-10-25 12:59:34
我不明白为什么即将到来的不工作,因为它看起来相当于“date_start_after = now”,但以某种方式运作不同。 – 2010-10-25 13:01:22