1

I'm using Michael Rog's Craft Calendars plugin.

I'm wondering if it's possible to limit events to specified owner category.

For example, I have a training entry with trainingType and trainingLevel category type fields.

While listing events is it possible to do something like:

{% set params = {
    calendar: 'myAwesomeCalendar',
    dateRangeStart: 'today',
    dateRangeEnd: now|date_modify("+1 month"),
    owner.trainingType = 'webinar',
    owner.trainingLevel = 'expert' 
} %}

{% for e in craft.calendars.events(params) %}
    <h1>{{ e.owner.title }}</h1>
    <p>Starts: {{ e.startDate  | date("Y-m-d") }}</p>
    <p>{{ e.owner.trainingType }} , {{ e.owner.trainingLevel }}
{% endfor %}

If not, how else would you approach this.

1

You can find info about how to do this in the docs: https://calendars.docs.topshelfcraft.com/guide/events-variable.html#How-it-Works

The EventCriteriaModel given by craft.calendars.events is used to query the owner elements from which the event instances are generated.

So, in your example above, you can use something like:

{% set params = {
    calendar: 'myAwesomeCalendar',
    dateRangeStart: 'today',
    dateRangeEnd: now|date_modify("+1 month"),
    trainingType: 'webinar',
    trainingLevel: 'expert' 
} %}

This tells Calendars:

  • Find entries where trainingType is "webinar" and trainingLevel is "expert"...
  • ...and if those elements have any event rules registered on the Calendar called myAwesomeCalendar...
  • ...return the instances of those events that occur in the next month.

(In this case, Calendars queries Entry elements, since that is the default. You could specify a different element type, however.)

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.