My config.toml for a multilingual site is organized like this:
### root variables
baseURL = "https://lagouille.netlify.com"
....
### params variables
[params]
[[Params.listeLangues]]
code = "fr"
[[Params.listeLangues]]
code = "en"
### params by language
[Languages]
[Languages.fr]
languageName = "Français"
weight = 1
myGlobalParameter = "foo"
...
And I have to put my line myGlobalParameter = "foo"
in all the languages sections.
I access it by {{ .Site.Params.myGlobalParameter }}
. Works like a charm.
As I am lazy, I want to only write this line once .
So I can do
[params]
[Params.global]
myGlobalParameter = "foo"
But now I have to access it with {{ .Site.Params.global.myGlobalParameter }}
and change all my code (not a real problem tho).
I tried a lot of things without succes to:
write them once
access it by the same {{ .Site.Params.myGlobalParameter }}
but i couldn’t. Is it possible ? Thanks.
bep
October 18, 2018, 4:48pm
2
I have updated the docs for this a little, but this should just work and be pretty clear:
I suspect that it is the params syntax below languages that is hard to get right.
1 Like
Dear Bep, thanks a lot for this update. It is more clear and simple.
But this is what I was previously doing. So I experimented a bit and I have a use case who do not work as described.
My repository is : https://github.com/divinerites/lagouille.com if needed (may be it is caused by some other parameter ?)
This is what I have:
[params]
[params.agenda]
id = "nc7pncf7kt3s"
root = "https://calendar.google.com/calendar/embed?"
[languages]
[languages.fr]
languageName = "Français"
[languages.fr.params.agenda]
enable = true
title = "Nos prochains évènements"
id = "ID EN FRANCAIS"
I put a test on my front page
id : {{ .Site.Params.agenda.id }}<b>
title : {{ .Site.Params.agenda.title }}<br>
.Site.Params.agenda.title
is correctly set to the french value
When I comment the id
in the french section => .Site.Params.agenda.id
is empty (But I have a default value in the params section !)
If i have the id in french section => .Site.Params.agenda.id
is correctly set to french value.
I confess that I really think I do something wrong. Such a bug would have been reported before, but I just can’t find a solution after 3 days trying, and your post confirmed that I was trying to do the right thing.
I can reproduce this unexpected behaviour with a minimal site.
Unfortunately Github is broken right now, so I can’t create/push any commit. Will do later when it is working. ~
Repository available : https://github.com/divinerites/mytest
In the mean time share the simple code and (unexpected) result.
You can see that if i comment ‘title’, i get an empty value and not the “root” one.
[languages.fr.params.agenda]
# title = "languages.fr.params.agenda.title FRANCAIS"
This is my code (again sorry, but github is broken. Zip available on request (couln’t find how to add a zip) )
### config.toml
[params]
[params.agenda]
id = "params.agenda.id RACINE"
title = "params.agenda.title RACINE"
[params.global]
robots = "index,follow"
[params.global.agenda]
id = "params.global.agenda.id RACINE"
title = "params.global.agenda.title RACINE"
[[params.listeLangues]]
code = "fr"
[[params.listeLangues]]
code = "en"
[languages]
[languages.fr]
languageCode = "fr-fr"
title = "languages.fr.title"
[languages.fr.params.agenda]
enable = true
id = "languages.fr.params.agenda.id FRANCAIS"
# title = "languages.fr.params.agenda.title FRANCAIS"
[languages.en]
languageCode = "en"
title = "languages.en.title"
[languages.en.params.agenda]
enable = true
# id = "languages.en.params.agenda.id ANGLAIS"
title = "languages.en.params.agenda.title ANGLAIS"
my simple ìndex.html`
### index.html
<h2> Paramètre globaux</h2>
.Site.IsMultiLingual : {{ .Site.IsMultiLingual }}<br>
.Site.Languages : {{ .Site.Languages }}<br>
.Language.Lang : {{ .Language.Lang }}<br>
.Site.Language : {{ .Site.Language }}<br>
.Site.LanguageCode : {{ .Site.LanguageCode }}<br>
<h2>Parametres de params.agenda]</h2>
<p>
.Site.Params.agenda.id : {{ .Site.Params.agenda.id }}<br>
.Site.Params.agenda.title : {{ .Site.Params.agenda.title }}<br>
</p>
<h2>Parametres de params.global.agenda]</h2>
<p>
.Site.Params.global.agenda.id : {{ .Site.Params.global.agenda.id }}<br>
.Site.Params.global.agenda.title : {{ .Site.Params.global.agenda.title }}<br>
</p>
and the “broken” result. I should see
.Site.Params.agenda.title : params.agenda.title RACINE
instead on an empty value .
If this is confirmed, do you want me to fill an issue ?
Well, I tested it in every way and make a repo who demonstrate in a clearer way (i think) this wrong behaviour.
I filled a bug https://github.com/gohugoio/hugo/issues/5357