1

I am using Michael Rog's Calendar plug-in and am trying to pass the calendar ID to an include.

Parent template:

{% include '_includes/_calendar' with {'calendarId': '1'} %}

_includes/_calendar:

{% set params = {
    calendarId: '{{ id }}',
    dateRangeStart: 'today',
    dateRangeEnd: '+36 months'
} %}

{% for entry in craft.calendars.eventData(params).events %}
    <li>
        <time>{{ entry.startDate  | date("D d M") }}</time>
        <h3>{{ entry.element.title }}</h3>
        {{ entry.element.eventDescription }}
    </li>

{% endfor %}

I am not getting any results for that.

If I change the params to

{% set params = {
    calendarId: '1',
    dateRangeStart: 'today',
    dateRangeEnd: '+36 months'
} %}

I get the results for the correct calendar.

I haven't used includes with variables like this before. Where am I going wrong?

2

Two things, the variable you send in is called calendarId, not id. Also, inside twig code (like the set function), you don't use twig tags, just the variables directly. Try to change the params object to:

{% set params = {
    calendarId: calendarId,
    dateRangeStart: 'today',
    dateRangeEnd: '+36 months'
} %}

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.