I can't get pages in a specific language

routes
languages

#1

Hi everyone,

I have a problem getting children of a page in a specific language. I asked (link -> Remove parent page name in subpage url)
few months ago to remove parent page in subpage url. Thats run correctly but the problem is that my page is multilanguage and when I’m going to find the subpages of my page allways get default language pages and kirby can’t find the page:

$categories = page('blog')->children()->pluck('uri', ','); //<-- here gets children of default language
    $i = 0;

    while($i < count($categories)) {
      if($page = page($categories[$i].'/'.$uid)) {
        return site()->visit($page);
      }
         $i++;
    }

I’ve tried using ->content(‘language code’) and creating a custom filter (link -> Filter child pages by available translations) but I can’t solve it.

Some ideas? :slight_smile: thanks!


#2

Have you tried this: https://k2.getkirby.com/docs/cookbook/multilanguage-secrets#filtering-content-by-language


#3

Nothing… The page goes blank


#4

Is the above code from a route?


#5

Yes is a route but that’s an example. This is my code:

array(
        'pattern' => 'en/our-news/(:any)',
        'action'  => function($uid) {

            if($page = page('en/our-news/'.$uid)) {
                go($page->parent());
            } else {

                $categories = page('nuestras-noticias')->children()->pluck('uri' ',');
                $i = 0;

                foreach($categories as $category){
                    echo $category . '<br>';
                }

                while($i < count($categories)) {
                    if($page = page($categories[$i].'/'.$uid)) {
                        echo $categories[$i];
                        echo $uid;
                        return site()->visit($page, 'en');
                    }

                    $i++;
                }
            }
            return false;
        }
    ),

#6

I can’t look into this now, will try tonight.

What I do seem to understand is that you are using URL-Keys for each language, right?


#7

Yes, I’m using it foreach one


#8

You are using site()->visit($page, 'en');. But I guess you would need to call it with the language code of the language that you want, not hardcoded en.


#9

That route only addresses the URLs starting with en anyway?


#10

Yes, I have that route only for ‘en’ routes. My page is in Spanish (default language) and when y search the children of the page ‘nuestras-noticias’ the method gets Spanish children, not English children so in the while It isn’t being found the page.


#11

Yes, this route I only use for ‘en’ routes


#12

I’ve tried to print the children in a template and there the values ​​change depending on the language. I don’t understand why with the same code, in config file doesn’t run same as in a template. Does this help you?

I have also put page('our-news') (The name of the page of the English version) instead of page('nuestras-noticias') but it does not work either.


#13

Sorry, I haven’t had time to dive into this yet.


#14

Could you send me your project as a zip for testing, I don’t have the time to recreate such a setup at the moment. Then I can look into it over the weekend.