But for the rest, I would need the code in the snippet, because inside, you would have to apply the same filter to actually only get the future children.
Why are you trying to get the parent and then two times the children instead of calling the children directly in that snippet?
That’s the reason for my next question (sorry!):
For the sections ‘concerts’ or ‘seminars’ i just use $data->children()->visible()…
But in the first and upper ‘all-events’ section there is an overview of all different kinds of events. Thats why i grab all the grandchildren of the parent ‘kalender’.
Now, that we filter out all sections that don’t have subpages, my overview section is fitered out as well.
If you don’t mind i’d be thankful for a hint how to keep my ‘all-events’ section (that has no subpages) on top of the filtered sections.
What is kb() in the above? A custom method?
Good question. I thought it was a regular Kirby method. I probably just copied it from somewhere else. I changed it to html() now.
Why is it the same if you filter by date in your snippet? After all, each section has its own snippet, doesn’t it?
After all, you wrote above that you wanted to load sections that don’t have subpages as well, don’t you? That’s why the if statement didn’t work for you.
Of course, you could put the if statement back into the relevant snippets, if you prevent the snippet to output anything that is useless if there are no relevant children.
Now i got it! In the snippet i had to put the rest of my HTML markup inside the if statement as well. Before i only had the foreach loop inside, so the headline still showed up, obviously. Thanks again!
<?php if($data->children()->filter(function($p) {
return $p->date() <= time();
})->count()): ?>
<!-- stuff that should be filtered -->
<?php endif ?>
How can one donate for your help?
(I found your PayPal link)
I have a follow-on question. I’d like to switch the operator depending on the state of a radio button.
If button 1 is selected the operator should be “<”: return $p->date() < time();
If button 2 is selected the operator should be “>=”: return $p->date() >= time();
When i try to use the variable $termin_operator inside the function like this: return $p->date() $termin_operator time();
i get: syntax error, unexpected '$termin_operator' (T_VARIABLE), expecting ';'
I read about global vs local variables in functions etc. but i couldn’t get it to work.
I don’t pretend to be any good at PHP, i’m learning but I’m pretty sure you cant use variables in place of things like operators. I think you need something more along the lines of this:
First of all: what sort of value does $_POST['termine']return? True? Do a var_dump($termin_operator) if not sure. Depending on what it does return, we can then act on it.
the operator contains an empty string if it is not set. So even if using a variable as a comparison operator was possible (which it is not), then using an empty string would definitely return an error.
Good night to you, too.
Edit: Assuming that you don’t want to filter if $termin_operatoris an empty string and leaving the rest as is, we would end up with this: