It doesn’t run in this way, but the problem is that I wan’t just to show the first event of the foreach. I tried with an index before, but I have to put a if in the foreach to have just the events that doesn’t begin and my index is false.
$allNow = $site->find('expositions','events')->children()->visible()->filter(function($child) {
return $child->date(null, 'debut') > time();
});
// then loop over this to show all events
To get only the first event:
$firstEvent = $allNow->first(); // no loop, no if
echo $firstEvent->title();
Can I do that with current event ?
Something like return $child->date(null, 'begin') > time() && $child->date(null, 'end') < time() && $child->place() == "thisPlace"; ?
You can use multiple conditions in the filter callback (not on a single event, though, because filters only work with a collection), however, your logic doesn’t really make sense and will probably not return anything (with a start date in the future but an end date in the past)…
I’m trying to compare $child with element in the page, but when I write something like $page->date() or $page->title() , $page seems to be undefined, I wrote it out of the function but same problem…
Please post your example code that doesn’t work as expected. If you want to use a variable you have defined outside the callback, you have to use use()
Example: