Using different layout for different languages for a same page

How can I use different layouts for a same page?

Right now I have

  • content/ja/about/_index.html
  • content/about/_index.html
  • layout/about/list.html
  • layout/ja/about/list.html

I tried to understand the documentation about lookup order but could not figure out what to do with multi lingual.

Also, I feel like maybe I should do content/about.html and content/ja/about.html but maybe not? What is the correct way to do this?

If I can write go lang on content page but I believe go is only executed on layout so we do need to separate layout files for those languages right?

Never tried it, but I believe that you need to encode the language into the filename of the template, see this page for examples: Template lookup order | Hugo (The Language section near the top, and the example tables in the second part of the page, they have example template names for a French site)

2 Likes
  • layout/about/list.html
  • layout/about/list.ja.html

If list.html works for the English version, then list.js.html should match on the Japanese version.

Put the language between the layout name and it’s extension.

1 Like

Thank you everyone!

That worked

  • layout/about/list.html
  • layout/about/list.ja.html

(side note: I was gonna say I have already tried above solution and failed. BUT, once I delete public folder and run hugo server again, then it worked. I have been confused with other stuff as well but turned out hugo server did not update the site as I change stuff even when I terminate it and run hugo server again. Even with hugo serve -D --cleanDestinationDir --disableFastRender, it requires manually deleting public. Is this an expected behavior? I made sure it is not browser cache problem.)

According to docs at Configure Hugo | Hugo

cleanDestinationDir
When building, removes files from destination not found in static directories

It does not remove other files there from previous builds. So files not touched with current build will not be removed.

So unless you have a stable set of pages that have only content changes or adding pages.

I recommend to remove public every time you remove some pages or change their destination path.

1 Like

Thank you everyone :heart:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.