I’m wondering what’s the best and cleanest way to filter (grand-)child pages by available languages? In my template I only want to display those children that have a translation in the currently selected language.
I was thinking of something like this
foreach ($page->children()->filterBy('languages', '*=', $site->language()->code() as $child) {
....
}
Should I create a custom filter, use the filter method with a callback or is there actually a build-in method that I didn’t find yet?
I think that article is a bit outdated cause it was written for Kirby 1, so there might now be an easier way of doing it using a custom filter. An alternative would be to use a separate language field in the files.
I totally agree with @FabianSperrle; Kirby core should definitely expose available translations/language versions of pages as standard data fields —for both filterBy and//or sortBy method chaining. Any plans @bastianallgeier?
P.S. @distantnative and @texnixe: the solution above does not looks very performant to my eyes. If you have and input on optimizations, I’m eager to listen up. Even though I’m still convinced, Kirby core should expose language fields to filterBy by default.