### Install Apostrophe Event Module Source: https://github.com/apostrophecms/event/blob/main/README.md Installs the `@apostrophecms/event` module into an Apostrophe project using npm. This is the initial step to integrate event functionality. ```bash npm install @apostrophecms/event ``` -------------------------------- ### Display Event List with Filters and Pagination (Nunjucks) Source: https://github.com/apostrophecms/event/blob/main/modules/@apostrophecms/event-page/views/index.html This snippet renders a list of events, including filtering options and pagination controls. It uses Nunjucks macros for rendering filters and pagination, and displays event titles and start times. Dependencies include the '@apostrophecms/pager' module and custom filters. ```nunjucks {% extends data.outerLayout %} {% import "filters.html" as filters %} {% import '@apostrophecms/pager:macros.html' as pager with context %} {% block title %}{{ data.page.title }}{% endblock %} {% block main %} {{ __t('aposEvent:filters') }} -------------------------------- {% render filters.render({ filters: data.piecesFilters, query: data.query, url: data.page._url }) %} {{ __t('aposEvent:pluralLabel') }} ------------------------------------ {% for piece in data.pieces %} ### [{{ piece.title }}]({{ piece._url }}) {{ piece.start | date('MMMM D, YYYY') }} at {{ piece.start | date('h:mma') }} {% endfor %} {{ pager.render({ page: data.currentPage, total: data.totalPages, class: 'blog-pager' }, data.url) }} {% endblock %} ``` -------------------------------- ### Configure Apostrophe Project with Event Modules Source: https://github.com/apostrophecms/event/blob/main/README.md Configures the ApostropheCMS project to include the event piece type (`@apostrophecms/event`) and the event page type (`@apostrophecms/event-page`). This is done in the `app.js` file. ```javascript require('apostrophe')({ shortName: 'my-project', modules: { // The main event piece type module '@apostrophecms/event': {}, // The event page module '@apostrophecms/event-page': {} } }); ``` -------------------------------- ### Create Special Event Page Module Source: https://github.com/apostrophecms/event/blob/main/README.md This JavaScript code demonstrates how to create a corresponding page module for the custom 'special-event' piece type. It extends the '@apostrophecms/event-page' module to handle the display of these custom events on a page. ```javascript // modules/special-event-page/index.js module.exports = { extend: '@apostrophecms/event-page' } ``` -------------------------------- ### Build Event Filter URL with Date Parameters (Twig) Source: https://github.com/apostrophecms/event/blob/main/modules/@apostrophecms/event-page/views/filters.html This macro constructs URLs for filtering events by year, month, and day. It utilizes the `build` utility to append date-specific query parameters to a base URL, allowing for dynamic filtering of event listings. ```twig {% macro here(url, changes) %} {{ url | build({ year: data.query.year, month: data.query.month, day: data.query.day }, changes) }} {% endmacro %} ``` -------------------------------- ### Enable Event Page Type in Apostrophe Source: https://github.com/apostrophecms/event/blob/main/README.md Enables the `@apostrophecms/event-page` type for editors to select when creating new pages. This configuration is added to the `@apostrophecms/page` module's options in `modules/@apostrophecms/page/index.js`. ```javascript // modules/@apostrophecms/page/index.js module.exports = { options: { types: [ { name: '@apostrophecms/home-page', label: 'Home' }, // Adding the event page type { name: '@apostrophecms/event-page', label: 'Event Page' } ] } }; ``` -------------------------------- ### Render Event Filter Fragment (Twig) Source: https://github.com/apostrophecms/event/blob/main/modules/@apostrophecms/event-page/views/filters.html This Twig fragment renders filter lists for events based on available year, month, and day filters. It iterates through each filter type, displaying the translated label and a link to the filtered event list using the `here` macro. ```twig {% fragment render(data) %} ### {{ __t('aposEvent:filterYear') }} {% for year in data.filters.year %}* [{{ __t(year.label) }}]({{ here(data.url, { year: year.value }) }}) {% endfor %} ### {{ __t('aposEvent:filterMonth') }} {% for month in data.filters.month %}* [{{ __t(month.label) }}]({{ here(data.url, { month: month.value }) }}) {% endfor %} ### {{ __t('aposEvent:filterDay') }} {% for day in data.filters.day %}* [{{ __t(day.label) }}]({{ here(data.url, { day: day.value }) }}) {% endfor %} {% endfragment %} ``` -------------------------------- ### Create Special Event Piece Type with URL Field Source: https://github.com/apostrophecms/event/blob/main/README.md This JavaScript code defines a new 'special-event' piece type by extending the '@apostrophecms/event' module. It includes a custom 'eventUrl' field of type 'url' and configures UI labels for the module. ```javascript // modules/special-event/index.js module.exports = { extend: '@apostrophecms/event', options: { label: 'Special Event', pluralLabel: 'Special Events' }, fields: { add: { eventUrl: { label: 'Event URL', type: 'url' } }, group: { basics: { fields: [ 'eventUrl' ] } } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.