🚚 How to migrate to Kirby Tips & tutorials
Skip to content

Filter by language

In a multi-language setup, Kirby falls back to returning the contents of the default language if it can't find a translated content file.

To prevent this, for example when displaying the pages for a menu or a list of articles, we have to filter the pages. Here's how to do this using Kirby's translation() method within a filter callback:

<?php

$translatedPages = page('somepage')->children()->filter(
    fn ($child) => $child->translation(kirby()->language()->code())->exists()
);

Author