【问题标题】:How do you loop through past items in a search in a Zotonic template?您如何在 Zotonic 模板的搜索中遍历过去的项目?
【发布时间】:2010-10-23 19:02:13
【问题描述】:

我希望能够在模板中循环浏览过去的事件:

{% 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 模板的搜索中循环遍历过去的项目?

【问题讨论】:

    标签: templates search zotonic


    【解决方案1】:

    您可以使用查询搜索模型的 date_start_before 术语,这显然没有记录,尽管我确实在 search_query.erl(第 293 行)中找到了它。

    虽然我认为您的查询应该检查 pivot_date_end 而不是 pivot_date_start。

    为了使其更易于访问,您可以向 mod_search.erl 模块添加一个处理程序(很像 upcoming),最终还要修改

    mod_search 模块实现了大多数搜索。

    另见http://zotonic.com/documentation/761/the-query-search-model

    欢迎使用补丁 :-)

    【讨论】:

    • date_start_before 需要一个参数。我用 m.search[{query cat='event' sort="rsc.pivot_date_start" date_start_before=now}]
    • 奇怪的是,即将到来的似乎对我不起作用。可能是我的活动没有设置 date_end。
    • 我不明白为什么即将到来的不起作用,因为它看起来等同于“date_start_after=now”,但不知何故运作方式不同。
    • 实际上它会检查旋转日期:pivot_date_start 这个日期是 date_start 的规范化(和索引)版本。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-16
    • 1970-01-01
    • 1970-01-01
    • 2019-12-03
    • 2012-08-20
    相关资源
    最近更新 更多