Fetch page from another language using .GetPage

I’m trying to get the home page from another language than the current one from the template with .GetPage to no avail.

I guess what I need is the equivalent of {{< relref path="document.md" lang="ja" >}} but for .Site.GetPage.

I could not find which string to pass as .GetPage parameter to get what I want :frowning:

Depending if you do translation by filename or content dir, have you tried these? (untested)

{{ .Site.GetPage "document.ja.md" }}
{{ .Site.GetPage "ja/document.md" }}

Yes I tried both.

I know the answer.

Awesome! :slight_smile: Now my telekinesis is a bit rusty, would you mind writing it down for me, unless there’s something obvious I’m missing :wink:

If you just pass the page name, "document", what language does it return?

The current one (as designed).

To give you more context, I want pages with no translated content to still display a list of alternate languages pointing to the home page of said languages. So for example, on a blog article (english only) I’m trying to grab the “japanese homepage” in order to use its .Permalink.

Currently I resolved to building the url string myself with .BaseURL and .Lang but I’m looking for a more scalable solution.

You need you call .GetPage from the relevant Site.

So, variants of:

{{ range .Sites }}
{{ .GetPage "foo" }}
{{ end }}

{{ .Sites.First.GetPage "foo" }}

{{ range .Translations }}
{{ .Site.GetPage "foo" }}
{{ end }}

Etc.

3 Likes

Oh I see… Thanks! I completed forgot about .Sites:man_facepalming:

Thanks to you both and a Happy New Year! :confetti_ball:

1 Like

Telekinesis is moving things with your mind.
Telepathy is psychically accessing another’s mind.
A pedant is a person who is excessively concerned with formalism, accuracy, and precision, or one who makes an ostentatious and arrogant show of learning. They probably make half-decent moderators.

The best part of this is that @regis probably has access to @bep’s laptop camera, since the implied threat meant manipulating fingers to type an answer! Whaaaaaat?! Happy New Year!

1 Like

Ah ah ! Happy New Year :joy: