0

I have an entry assigned to a specific category. I want events from exp:calendar:cal that share the same category to be displayed on the same page. When I hard code the category ID it works like a charm, but I want to know how I can pass the category ID dynamically. I've tried embeds, snippets and Stash embeds and I can't get anything to work.

Here's the calendar code...

<ul>
{exp:calendar:cal channel="calendar_events" date_range_start="today" date_range_end="12 months" event_limit="4" enable="categories|custom_fields" related_categories_mode="yes" custom_fields="yes" category="[SNIPPET? EMBED? STASH?]"}
<li>{event_start_date format="%M %j"}<a href="{path='calendar/event'}/{if event_recurs}{event_start_date format="%Y/%m/%d"}/{/if}{event_id}" title="{title}">{title}</a></li>{/exp:calendar:cal}
</ul>

And here's what I'm using to grab the category ID of the current page...

{exp:channel:entries channel="cool_stuff" disable="{gv_disable}"}
{categories}{category_id}{/categories}
{/exp:channel:entries}

Thanks in advance to anyone who can help at all!

2 Answers 2

0

It depends on how you are locating the channel entry you want to use to give you the category ID.

If the category is included in the URL you can use something like Low's Seg2Cat to get the Category ID from the relevant slug in the URL - perhaps like this (if the category info is in segment 2 of the URL):

{exp:calendar:cal ... category="{segment_2_category_id}"}

If that is not possible, you could use Stash to capture the entry_id and insert it into the calendar tag - though often it can be tricky to get stash to work, as parse order can sometimes mean that stash doesn't find the value until after you need it etc.

Or you could use a standard EE embed.

Deciding which is best really depends what else is going on on the site.

The other thing to think about though is what happens if the Entry you are focused on is assigned to more than one category... which one will you want the calendar call to use?

HTH

1
  • Thanks for your input! I did get something to work: I put my calendar code in an embed, grabbed the category ID in a snippet and passed the result of the snippet to the calendar through an embed variable. Now just trying to account for no results and multiple categories...
    – Matt
    Commented Apr 13, 2018 at 12:01
0

I found a partial solution to this problem. Perhaps it will help someone.

I put the calendar code in an embed with an embed variable called entry-category:

<ul>
{exp:calendar:cal channel="calendar_events" date_range_start="today" date_range_end="12 months" event_limit="4" enable="categories|custom_fields" related_categories_mode="yes" custom_fields="yes" category="{embed:entry-category}"}
<li>{event_start_date format="%M %j"}<a href="{path='calendar/event'}/{if event_recurs}{event_start_date format="%Y/%m/%d"}/{/if}{event_id}" title="{title}">{title}</a></li>{/exp:calendar:cal}
</ul>

Then used a snippet to grab the category ID of the current page and passed that into the embed:

{embed="includes/category-cal" entry-category="{sn_event-category}"}

I added a pipe into the snippet to account for multiple categories. If there's more than one category if results in a stray pipe at the end, but it works!

{exp:channel:entries channel="cool_stuff" disable="{gv_disable}"}
{categories}{category_id}|{/categories}
{/exp:channel:entries}

The only remaining problem is accounting for instances where there are no events that match the category ID or IDs of the page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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