Hi
I’m using calendar-board with Bastian’s calendar
I try to display every events for each days. So, based on the example from documentation, I did :
<?php foreach($pages->find('calendar/year-2017/day-2017-02-09')->events()->toStructure() as $event): ?>
<?php echo $event->hour()->html() ?>
<?php endforeach ?>
It’s working, it shows one event every days but I would like to get every events for each days. Can you advice me ?
texnixe
February 11, 2017, 9:23pm
2
Should be something like this:
<?php
foreach($pages->find('calendar/year-2017')->children() as $child):
$events = $child->events()->toStructure();
foreach($events as $event):
echo $event->hour()->html();
endforeach;
endforeach;
?>
1 Like
I get a blank page on Kirby 2.3.2. I think it’s due to my rewriting of your code, did you mean
<?php foreach($pages->find('calendar/year-2017')->children() as $child): ?>
<?php if ($events = $child->events()->toStructure()); ?>
<?php foreach($events as $event):?>
<?php echo $event->hour()->html() ?>
<?php endforeach ?>
<?php endif ?>
<?php endforeach ?>
texnixe
February 11, 2017, 10:23pm
4
If you haven’t done it yet, please enable debugging in your config.php
c::set('debug', true);
to get an error message instead of a blank page.
Nice trick, I get a message for a semilicon. I corrected then. But the strange thing is that I have exactly the same thing as previously : my event is display on every days
<?php foreach($pages->find('calendar/year-2017')->children() as $child): ?>
<?php if($events = $child->events()->toStructure()): ?>
<?php foreach($events as $event):?>
<?php echo $event->hour()->html() ?>
<?php endforeach ?>
<?php endif ?>
<?php endforeach ?>
texnixe
February 11, 2017, 11:10pm
6
Could you let me know your structure and what the content in the files looks like?
Well this is my reduced code, I hope it can help
<?php snippet('header') ?>
<main class="main" role="main">
<h1><?php echo $page->title()->html() ?> template</h1>
<?php
date_default_timezone_set('UTC');
setlocale(LC_ALL, 'en_US');
// get the year and number of week from the query string and sanitize it
$year = filter_input(INPUT_GET, 'year', FILTER_VALIDATE_INT);
$month = filter_input(INPUT_GET, 'month', FILTER_VALIDATE_INT);
// initialize the calendar object
$calendar = new calendar();
// get the current month object by year and number of month
$currentMonth = $calendar->month($year, $month);
?>
<section class="month">
<table>
<tr>
<?php foreach($currentMonth->weeks()->first()->days() as $weekDay): ?>
<th><?php echo $weekDay->shortname() ?></th>
<?php endforeach ?>
</tr>
<?php foreach($currentMonth->weeks(6) as $week): ?>
<tr>
<?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-2017')->children() as $child): ?>
<?php if($events = $child->events()->toStructure()): ?>
<?php foreach($events as $event):?>
<?php echo $event->hour()->html() ?>
<?php endforeach ?>
<?php endif ?>
<?php endforeach ?>
</td>
<?php endforeach ?>
</tr>
<?php endforeach ?>
</table>
</section>
</main>
<?php snippet('footer') ?>
and my calendar-board-day.txt file in the calendar/year-2017/1-day-2017-02-09 folder
Title: 09-02-2017
----
Events:
-
hour: 03:00
topic: hgf
associates: hjg