$page->render() for translations

To transform a Kirby site into a static one, I use $page->render() to grab the complete html of a single page – unfortunately this doesn’t seem to work for translations!? It always returns the html of the default language. Any ideas how the render a translation of a page?

Code snippet (incomplete)

$html = $page->render();
$file = $kirby->root('static') . DS . $page->id() . DS . 'index.html';
F::write($file, $html);

More information

Any ideas?

Hmm, I have no experience with this, but based on how kirby handles multilingual things in routes, it might be an idea to check out $site->visit() (https://getkirby.com/docs/reference/objects/site/visit)?

1 Like

This “kind of” works :wink: :joy:

I can grab the translated content with $site->visit() :tada: … but once used, I can’t switch (back) to another language again. That means it is not possible for me to export all languages in one step. But my workaround is now to export each language separately.

Thanks for the hint, @bvdputte :+1:

1 Like

Don’t know your exact context, but what if you loop through all languages, each time visiting the site in the correct language and then export the stuff?

That‘s exactly what I did, but visit() worked only once correctly and didn’t change the language again afterwards. But that‘s no big deal. :wink: