I18n front matter params fallback


I have two versions of the same localized page:


title: English title
param1: value1
param2: value2


title: Spanish title
param2: value2-spanish

If I call {{.Params.param1}} in a template, I get empty value on the Spanish page. Is it possible to set up a fallback so that it will be taken from the main English front matter in case if it’s absent in the Spanish front matter?

It’s possible, but I’m not sure how simple… Something like this:

{{ $param := .Params.param1 }}
{{ if not $param }}
{{ with (index .Translations 0) }}
{{ $param = .Params.param1 }}
{{ end }}
{{ end }}

The above defaults to the first translation, which would be English when you’re on a Spanish page, assuming English is the first in the sorted list (weight=1 or something).