Embed a date-specific event calendar
Drupal 7 will no longer be supported after January 5, 2025. Learn more and find resources for Drupal 7 sites
It is fairly simple to display an event calendar for all event content on a site, but sometimes we need to display a date-specific calendar, e.g. for an event listing view. To do this, follow the instructions below.
Modules needed:
1. Create a new content type for events (e.g. 'events') and add starting and ending date fields. You can create now create your desired event content.
2. Add a new calendar view from the existing template in the calendar module(admin/structure/views add-template). From the list, you should select "A calendar view of the 'field_yourfieldname' field in the 'node' base table."(Display type of the view: Month)
3. In the edit mode of your calendar view, under filter criteria, select the event content type that you created above. Also add a contextual filter - 'Content: Nid'. Save the view.
4. Create a new view for your event listing. This view should have a page display. Under filter criteria, select the event content type that you created above. Add 'Content: Nid' as a new field and tick the option 'Exclude from display' in the configuration page. Add another field, 'Global: PHP', for grabbing the current date and passing it as an argument to the calendar view. You should write 'print date("Y-m")' in the Output Code field and tick the option 'Exclude from display' in the configuration page.
5. Embed the calendar view in your event listing by adding a new field: 'Global: View'. (See the attached image for the configuration of this field.) Here you should specify the name of your calendar view in the View setting section and also specify the views display type. Then, you should add '[%php]/[%nid]' as a contextual filter for the calendar view. Save the view. Your customized event listing is now ready!
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion
Still on Drupal 7? Security support for Drupal 7 ended on 5 January 2025. Please visit our Drupal 7 End of Life resources page to review all of your options.