Calendar Issues

Hi, I’m using the Calendar plugin by @molocLab and running into a problem which I can seem to work around.

I’m trying to integrate this with @bastianallgeier calendar plugin which is working fine. I’m currently showing a month view and have the calendar working in the panel however when I try and output any events into the calendar I’m getting issues.

This is the code at present:

<?php foreach($currentMonth->weeks(6) as $week): ?>
        <?php foreach($week->days() as $day): ?>
            <td<?php if($day->month() != $currentMonth) echo ' class="inactive"' ?>><?php echo ($day->isToday()) ? '<strong>' . $day->int() . '</strong>' : $day->int() ?>

                <?php foreach($pages->find('calendar/year-2016/day-2016-07-25')->events()->toStructure() as $event): ?>
                    <div class="item">
                        <?php echo $event->topic()->html() ?>

                <?php endforeach ?>

        <?php endforeach ?>  
<?php endforeach ?>

The above code works as intended by repeating the event over the course every day of the month.

I then changed the foreach loop to the following to try and change the date for each day:

  <?php foreach($pages->find('calendar/year-2016/day-2016-07-' . $day->int())->events()->toStructure() as $event): ?>

When I change the code in the loop to make it work for each day i get the following error:

 Fatal error: Uncaught Error: Call to a member function events() on boolean in /srv/users/chris/apps/01-      home/public/projects/vd/site/templates/calendar.php:53 Stack trace: #0 /srv/users/chris/apps/01-home/public/projects/vd/kirby/toolkit/lib/tpl.php(22): require() #1 /srv/users/chris/apps/01-home/public/projects/vd/kirby/kirby/component/template.php(85): Tpl::load('/srv/users/chri...', NULL, true) #2 /srv/users/chris/apps/01-home/public/projects/vd/kirby/kirby.php(619): Kirby\Component\Template->render(Object(Page), Array) #3 /srv/users/chris/apps/01-home/public/projects/vd/kirby/kirby.php(607): Kirby->template(Object(Page), Array) #4 /srv/users/chris/apps/01-home/public/projects/vd/kirby/kirby/component/response.php(29): Kirby->render(Object(Page)) #5 /srv/users/chris/apps/01-home/public/projects/vd/kirby/kirby.php(686): Kirby\Component\Response->make(Object(Page)) #6 /srv/users/chris/apps/01-home/public/projects/vd/index.php(16): Kirby->launch() #7 {main} thrown in /srv/users/chris/apps/01-home/public/projects/vd/site/templates/calendar.php on line 53

Is there something glaringly obvious I’m missing here?


You are trying to add an integer to a string, so your string is cast to integer, which results in an invalid page.

I tried the following but it made no difference? i though that would be enough tbh.


Could you test what you get when you echo this?

<?php echo 'calendar/year-2016/day-2016-07-' . (string)$day->int() ?>

When echoing -

 <?php echo 'calendar/year-2016/day-2016-07-' . (string)$day->int() ?>

I get


and so on for each day of the month, so that works as expected it just seems to be when I’m trying to loop through it doesn’t work.

Do you have pages for every day of the month? If the page does not exist, you’ll get an error

There isn’t pages for every day of the month, Using the calendar field it creates a page with a structure field for every date you have entries.

Would ->empty() work if it checked if it was available first?

Empty() only works on fields, you would have to check if the page exists, try this:

$p = $pages->find('calendar/year-2016/day-2016-07-' . (string)$day->int();
if($p): ?>
  <?php foreach ($p->events()->toStructure() as $event): ?>
    <div class="item">
        <?php echo $event->topic()->html() ?>
  <?php endforeach ?>
<?php endif ?>

I’d recommend to always check if an object exists before using a method on it.

That works perfect :slight_smile:

Thank you!

@MinmlCo I got here too late. :slight_smile:

Thanks @texnixe for helping him.