Forum

Thread tagged as: Question, Problem, Events

Perch Events - Calendar

Hi guys,

I'm working with the perch_events_calendar( ); calendar, and I'm trying to output a day name for all days - including days that have no events.

Please see below: blank-day.html:

<span class="day no-event"><span class="day_name"><perch:events id="day" format="D" /></span><perch:events id="day" /></span>

event-day.html:

<perch:before>
    <span class="day calendar_day-event"><span class="day_name"><perch:events id="eventDateTime" format="D" /></span><perch:events id="eventDateTime" format="j" /></span>
</perch:before>

This is working fine for the event-day.html template, but nothing comes up for the blank-day.html template. I've tried using eventDateTime for Blank Day, but that doesn't work - as expected.

I couldn't find anything online by search perch:events id="day" - is anyone able to help?

Thanks, Harry

Harry Ray

Harry Ray 0 points

  • 3 years ago
Duncan Revell

Duncan Revell 78 points
Registered Developer

Hi Harry,

perch:events id="day" is just a number - not a full date - so you can't get any other date information from it.

Thanks for the reply, Duncan.

Is there any way to achieve what I'm looking for at all, maybe using a different id?

Also, is there a way to change the output of:

<perch:events id="body" encode="false" />
Drew McLellan

Drew McLellan 2638 points
Perch Support

If you drop in <perch:showall /> do any of the fields contain the date?

Hi Drew, thanks for the answer!

Unfortunately not - using <perch:showall /> on the blank-day template doesn't show any dates, it only shows perch_page_path, day (which just contains the number), and perch_namespace.

Drew McLellan

Drew McLellan 2638 points
Perch Support

So the short answer is there's nothing to help you do that.

The long answer is yes you can, but you'll need to pass the month and the year into the template from the page, and then write a template filter to piece it all back together and format into a date.

Hi Drew,

I've built out a filter that will work for this, but how do I get the current date/year that the calendar is currently displaying, and feed it through? Is there a way to do this without needing the URL to reflect the calendar?

Thanks, Harry

Drew McLellan

Drew McLellan 2638 points
Perch Support

What do you have available on the page?

If I call <perch:showall /> from inside calendar.html, it returns a field that contains the selected_month - is there a way to feed info from calendar.html into blank-day.html?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Right, but on your page you must have more information about the date before the template is even used.

Sorry - I'm not sure I understand what you mean.

Here's the page - The calendar is a long way down: https://cargilfield.thirdfloordigital.net/default-page

The calendar is being used in a block (passed in via a PerchSystem variable). Nothing else on the page particularly ties into it!

Duncan Revell

Duncan Revell 78 points
Registered Developer

What is it that tells perch_events_calendar() to show January when the page loads? (It uses the current month/year).
So when the page loads, you should be able to use the month and year from the current time and pass them as variables.

If you click on the forward or back arrows, you should have ?d=yyyy-mm appended to the url, so in that case you would need to use perch_get('d') to get those values.

In fact, I suppose you could always use perch_get() and pass in a default value for situations where d is empty (check out https://docs.grabaperch.com/functions/utilities/perch-get/)

Thanks Duncan - I'm trying to do this without grabbing the URL though, I'm afraid!