I'm working on creating a simple calendar based on only native Craft fields. While coding this, I'm having a hard time getting the pagination to work properly.
The calendar currently lists all upcoming events this current month. Next/Previous should then paginate the calendar 1 full month forward/backward (not 1 month backwards from todays date, but all entries in the next/previous month).
According to Brandon, paginate.prevUrl/nextUrl won't map to specific date-based starting points. So, how do I tackle this problem then?
Here's my current code:
<div class="row">
<div class="small-12 medium-12 large-12 columns">
<div class="widget_event single_widget box_shadow">
<h3>Hva skjer i Filadelfia</h3>
{% set startDateTime = now|date_modify('0:00')|date('c') %}
{% set endDateTime = now|date_modify('first day of next month 4:00')|date('c') %}
{% set startDateParam = 'and, >= ' ~ startDateTime ~ ', < ' ~ endDateTime %}
{% set events = craft.entries.section('calendar').limit('15').startDate(startDateParam).order('startDate asc') %}
{% for event in events %}
<div class="event_list">
<div class="single_event">
<div class="date_left">
<p class="date">{{ event.startDate | date("d") }}.</p>
<p class="day">{{ event.startDate | date("M") }}</p>
</div>
<div class="title_middle">
<p class="title">{{ event.title }}</p>
<p class="desc">{{ event.body | hacksaw(words='75', allow='<b><strong><i><em>') }}</p>
</div>
<div class="time">{{ event.startDate | date("H:i") }}</div>
</div>
</div>
{% endfor %}
{% paginate craft.entries.section('calendar').limit(15) as pageEvents %}
{% for month, entries in pageEvents | group("postDate | date('F')") %}
<div class="event_nav text-center">
<span class="left left_arrow">{% if paginate.prevUrl %}<a href="{{ paginate.prevUrl }}">Previous Month</a>{% endif %}</span>
<span class="right right_arrow">{% if paginate.nextUrl %}<a href="{{ paginate.nextUrl }}">Next Month</a>{% endif %}</span>
</div>
{% endfor %}
{% endpaginate %}
</div>
</div>
</div>
Would it be "calendar/year/month" ? Which template should I specify it to load then? Since it's an include, and not a template in the way I think of a template?
– Filadelfia Jun 26 '15 at 07:30BTW: your current code works perfectly, except for the previous/next links, because of the Route part not being correct set up.
– Filadelfia Jun 26 '15 at 08:02<a href="{{ 'events/' ~ nextMonth|date("Y/n") }}">{{ nextMonth|date("F") }}</a>– Douglas McDonald Jun 27 '15 at 16:42[year]/[month]as your route, and specify the homepage template as the route template. The calendar could still be a template include. – Douglas McDonald Jun 27 '15 at 16:57