Eventlist - add different class to past event

Hi community,

I have an eventlist with upcoming current and past events. I want to add another class to the past events to show them transparent later on.
It seems to work mostly with the code below, but by using php inside the

s class attribute the div doesnt seem to notice its closing >.

Is there a simpler way of doing this in kirby?

<?php foreach($page->children()->listed() as $note): ?>
<div class="d-flex flex-row col-md-10 col-sm-12 pb-4 mb-4 border-bottom
<?php if(strtotime($note->date()->toDate('Y-m-d')) < time()): ?>
		muted
	<?php else: ?>
		normal
	<?php endif ?>
">

bye

Try using the e() helper…

<div class="d-flex flex-row col-md-10 col-sm-12 pb-4 mb-4 border-bottom <?php e(strtotime($note->date()->toDate('Y-m-d') < time(), 'muted', 'normal') ?>">

Using that condition inside the class definition makes your code rather unreadable.

$class = strtotime($note->date()->toDate('Y-m-d')) < time() ? ' muted' : ' normal'; // 

<?php foreach($page->children()->listed() as $note): ?>
<div class="d-flex flex-row col-md-10 col-sm-12 pb-4 mb-4 border-bottom<?php echo $class ?>">
1 Like

Yes, this is definitely better readable. I had to define the $class variable inside the foreach statement because $note is not defined before.

Thank you very much :slight_smile:

<?php foreach($page->children()->listed() as $note): 

$class=strtotime($note->date()->toDate('Y-m-d')) < time() ? ' muted' : ' normal';

?>

<div class="d-flex flex-row col-md-10 col-sm-12 pb-4 mb-4 border-bottom<?= $class ?>">