Pull Calendar Events — $calendar.find

Last Updated: Dec 13, 2024
documentation for the dotCMS Content Management System

You may pull specific Calendar events using the event Identifier, by calling either $dotcontent.find() or $calendar.find(), passing in the inode of the event:

#set($event = $calendar.find($event.identifier)) 

OR

#set($event = $dotcontent.find($event.identifier))

Pulling Recurring Events

The following code shows how to dynamically display recurring events on the front end.

Note: All events are only single pieces of content, and recurring events DO NOT exist in the content repository. These methods are only intended to be used to display the event's info more easily.

The inode of each recurring event is the same as the inode of the base event. The event returned by the find() call is an object with the start date and end date of the recurrence; the rest of the properties (including identifier and inode) are the same as the base event.

An easy way to use this when pulling events is to check if the event is recurrent:

#set($dateString = $date.format('yyyy-MM-dd',$UtilMethods.getCurrentDate()))

#set($nowlv = $date.toDate('yyyy-MM-dd',$dateString))
#set($now = $date.toDate('yyyy-MM-dd',$dateString))
#set($fromDatelv = $date.toDate('yyyy-MM-dd',$dateString))
#set($toDatelv = $date.toDate('yyyy-MM-dd',$dateString))
#set($calendarlv = $date.toCalendar($nowlv))
#set($dayOfWeeklv = $math.sub($calendarlv.get(7),1))

##sets start and end date range to look for this weeks events
#set($temp = $fromDatelv.setTime($math.sub($fromDatelv.getTime(), $math.mul(86400000,$dayOfWeeklv))))
#set($temp = $toDatelv.setTime($math.add($toDatelv.getTime(),$math.mul(86400000,$math.sub(6,$dayOfWeeklv)))))

##Optional Parameters
#set($tag="dotcms")
#set($keywordBox="Integrate")
#set($cat="3c540c2a-e901-48de-9f1a-a52d0bd6859f")

##Once the parameters have been set, now the event objects can be pulled
#set($events = $calendar.findEvents(${host.identifier}, ${fromDatelv}, ${toDatelv}, ${tag}, ${keywordBox}, ${cat}, "startDate", 1 , 10)) 
Number of events returned: $events.size()

#if($events.size() > 0) 
  #foreach ($event in $events) 
    #if($event.recurs)

      #set($event = $dotcontent.find($event.identifier))
      ##--OR--
      #set($event = $calendar.find($event.identifier)) 

      Event Title: $event.title
      Start Date: $event.startDate
      End Date: $event.endDate

    #end
  #end
#end

On this page

×

We Dig Feedback

Selected excerpt:

×