Structured Field: Hide entry when the date is over

Hey,

im using a Structure Field for dates. The code looks like this and works fine:

<?php foreach($page->termine()->toStructure()->sortBy('date', 'asc') as $termin): ?>
  <time datetime="<?php echo $termin->date('c') ?>"><?php echo $termin->date('d.m.Y') ?></time>
  <?php echo $termin->titel()->kirbytext() ?>
<?php endforeach ?>

The Blueprint is:

  termine:
    label: Termine
    type: structure
    style: table
    fields:
      titel:
        label: Titel
        type: text
      date:
        label: Datum
        type: date
        format: DD.MM.YYYY
        default: today

Is it possible to hide entries automatically when the day of the date is over?

Thanks in advance
Christian

With pages you can use ->hide() like that:

$adate = time();
$edate = strtotime($event->date());
if ($adate > $edate) {
  $event->hide();
}

With structure fields you would probably have to add another toggle field that defines the visibility. Otherwise you would have to delete the entry.

You can filter your entries by date:

$termine = $page->termine()->toStructure()->filterBy('date', '>', time())->sortBy('date', 'asc');
1 Like

Thats exactly what i was looking for, i didnt expect it to be that easy. Thanks for your help @thguenther and @texnixe