Step by step guide to create an event listing with calendar block in Drupal 7

Last updated on
30 April 2025

The contents of this guide should be tested along the Events calendar feature module as a working example. It is recommended to install and test this feature module first and dive into the step by step guide if needed.
If you get "The calendar row plugin is required when using the calendar style, but it is missing." notices, you should uninstall the feature and follow the steps below.

Below are the list of steps to create an events listing with a calendar block which filters them.

Download and enable the required modules

Create an Events content type

Go to Structure > Content types > Add content type (admin/structure/types/add) and create one with the following settings:

  • Name: Event
  • Fields: Add a field of type Date, field name event_date and label Date(s). In the field configuration screen check the "Required field" and "Collect an end date" checkboxes.
  • Create three or four events at the "Add content" (node/add/event).

Create a view to list events

Go to Structure > Views > Add new view (admin/structure/views/add) and create a view showing nodes of type "Event". Click on "Continue and edit".

Set the path of this page view to /events.

Add the following Contextual Filter (find the link at the Contextual Filters block when editing the view - often hidden under Advanced on the right - you need to click it to show more):

  1. In the search field type "Date: Date (node)" - select (Apply) then on the next menu
  2. "Add and configure contextual filters".
  3. go to "When the filter value is NOT in the URL", select "Provide default value".
  4. At Type in the drop-down list, select Current Date.
  5. Now scroll down to Date field(s) and select "Content: Event Date - start date (field_event_date)" / "field_event_date"- this is the date you set when creating the Content Type Event. You may have chosen different names - so be aware, especially if you already have dates used in other Content Types.
  6. Scroll down further to Method, select "AND".
  7. Save.

Create a calendar block for events

  1. Clone the view "Calendar" into "Events calendar". ›› UPDATE (2012-08-23, related to Calendar 7.x-3.4): you should rather use "Add view from template" on admin/structure/views depending on the appropriate field. Sample screenshots: "Add view from template"; Views + Calendar templates.
  2. Select the Block display and add a filter by content type so it only lists content of type "Event".
  3. Edit the Contextual Filter so it looks exactly the same as the one we configured at the Events view. ›› UPDATE (2012-08-23, related to Calendar 7.x-3.4): this is already set when using the appropriate template (see the screenshot in step 1).
  4. Save.

Add the calendar block to the events view

  1. Using Context module, create a context (admin/structure/context/add) so if the condition is the Events view, display the "Events Calendar" block in the sidebar
  2. Save the context
  3. Verify that opening /events lists the created events with a calendar block at the sidebar.

Add the following code to your default theme. Remember to change "yourtheme" by the name of the default theme. This code shoud reside at sites/all/themes/yourtheme/template.php

/**
 * Alters link url in calendar events block in order to filter events at /events
 *
 * @see template_preprocess_calendar_datebox()
 */
function yourtheme_preprocess_calendar_datebox(&$vars) {
  $date = $vars['date'];
  $view = $vars['view'];
  $day_path = calendar_granularity_path($view, 'day');
  $vars['url'] = 'events/' . $date;
  $vars['link'] = !empty($day_path) ? l($vars['day'], $vars['url']) : $vars['day'];
}

Help improve this page

Page status: Not set

You can: