Hi,
I have a date field inside a structure which can be left empty. Unfortunately I can’t figure out a way if the field is actually left empty, because the condition
$page->slots()->isNotEmpty() && $page->slots()->toStructure()->first()->time_from()->isNotEmpty()
evaluates as true
even if no date is set in the field. Is this a bug? Is there another way?
Many thanks,
Till
Just tested this in a Starterkit and seems to work as expected.
<?php foreach ($page->social()->toStructure() as $social): ?>
<li>
<?php if($social->date()->isNotEmpty()) {
echo 'Date is not empty';
} else {
echo 'Date is empty';
} ?>
</li>
<?php endforeach ?>
returns “Date is empty” for each item in this case, because all date fields are empty.
Which Kirby version are you using?
I just realized where the problem is, I did a faulty addition of dates and due to insufficient testing assumed the problem was with isNotEmpty(). It wasn’t, everything is working as expected.
I’m sorry for the confusion!