Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keithmancuso/d6170bd62bdff45e0adc68c9e324b5a6 to your computer and use it in GitHub Desktop.
Save keithmancuso/d6170bd62bdff45e0adc68c9e324b5a6 to your computer and use it in GitHub Desktop.
Month twig
{% spaceless %}
{% set d = craft.request.getParam('d') %}
{% set date = d ? d : 'today' %}
{% set month = craft.calendar.month({
date: date,
eventType: 'not spaceRental',
order: 'eventType desc',
firstDay: 1
}) %}
{% set dayCount = 0 %}
{% set weekCount = 0 %}
{
"name": "{{month.date |date_modify('+15 days') |date('F')}}",
"number": "{{month.date |date('m')}}",
"year": "{{month.date |date('Y')}}",
"weeks":
[
{% for week in month %}
{#% set weekCount = weekCount == 5 ? 1 : weekCount + 1 %#}
{% set weekCount = weekCount + 1 %}
{% if weekCount < 6 %}
[
{% for day in week %}
{% set dayCount = dayCount == 7 ? 1 : dayCount + 1 %}
{
"number": "{{day.date|date('j')}}",
"name": "{{day.date|date('l')}}",
"isToday": {{day.date| date('Y-m-d') == 'now'|date('Y-m-d') ? 'true' : 'false'}},
"events": {
{% for type, eventsInType in day.events | group('eventType') %}
"{{type}}": [
{% for event in eventsInType %}
{
"id": "{{ event.id }}",
"type": "{{event.eventType}}",
"category": "{{event.classCategory | length ? event.classCategory[0].slug}}",
"title": "{{ event.title | url_encode }}",
"url": "{{ event.id }}",
"body": "{{ event.body | url_encode }} ",
"instructor": "{{ event.instructors|length ? event.instructors.first().title : null }}",
"location": "{{ event.location|length ? event.location.first().title : null }}",
"calendarHandle": "{{ event.calendar.handle }}",
"start": "{{ event.startDate| date('g:iA') }}",
"end": "{{ event.endDate| date('g:iA') }}",
"images": [
{% for image in event.classImage %}
{
"url": "{{image.url}}"
}{{not loop.last ? ','}}
{% endfor %}
]
} {{not loop.last ? ','}}
{% endfor %}
] {{not loop.last ? ','}}
{% endfor %}
}
}{{dayCount != 7 ? ',' : null}}
{% endfor %}
] {{weekCount != 5 ? ',' : null}}
{% endif %}
{% endfor %}
]
}
{% endspaceless %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment