문제

I'm trying to promote a content on a page. This content should the upcoming content, i.e. the next one in all of the same type ("event").

Here's how metadata look like :

---
layout: event
date: 2013-12-11
title: Cool event
---

The docpad.coffee file collections configuration looks like (using moment.js):

collections:
    events: (database) ->
        database.findAllLive(type: "event", [date: -1])

    next_events: (database) ->
        @getCollection("events")
            .setFilter("upcoming", (event, searchString) ->
                return moment(event.eventDate, "YYYY-MM-DD").diff(moment()) < 0
            )

Finally in the index.html.eco :

<% for event in @getCollection("next_events").toJSON(): %>
    <h3><%= event.title %></h3>
<% end %>

Problem: it shows all my events, not only the future ones. When I use the events collection it works as intended (all events ordered by date desc). But no difference when I use the next_events collection. I know that to show only one I'll need to reduce the collection content with something like <% for event in @getCollection("next_events").toJSON()[0]: %>.

Any pointer greatly appreciated.

도움이 되었습니까?

해결책

Try this:

next_events: (database) ->
    @getCollection("events")
        .createLiveChildCollection()
        .setFilter("upcoming", (event, searchString) ->
            return moment(event.eventDate, "YYYY-MM-DD").diff(moment()) < 0
        )
        .query()
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top