Fix language handling in ExecuteAsTemplate

Fixes #6331
This commit is contained in:
Bjørn Erik Pedersen
2019-11-26 09:44:31 +01:00
parent 03b369e672
commit 96f09659ce
5 changed files with 51 additions and 26 deletions

View File

@@ -418,8 +418,7 @@ Fingerprinted: {{ $fingerprinted.RelPermalink }}
}},
{"execute-as-template", func() bool {
// TODO(bep) eventually remove
return isGo111()
return true
}, func(b *sitesBuilder) {
b.WithTemplates("home.html", `
{{ $var := "Hugo Page" }}
@@ -668,3 +667,30 @@ JSON: {{ $json.RelPermalink }}: {{ $json.Content }}
"JSON: /jsons/data1.json: json1 content",
"JSONS: 2", "/jsons/data1.json: json1 content")
}
func TestExecuteAsTemplateWithLanguage(t *testing.T) {
b := newMultiSiteTestDefaultBuilder(t)
indexContent := `
Lang: {{ site.Language.Lang }}
{{ $templ := "{{T \"hello\"}}" | resources.FromString "f1.html" }}
{{ $helloResource := $templ | resources.ExecuteAsTemplate (print "f%s.html" .Lang) . }}
Hello1: {{T "hello"}}
Hello2: {{ $helloResource.Content }}
LangURL: {{ relLangURL "foo" }}
`
b.WithTemplatesAdded("index.html", indexContent)
b.WithTemplatesAdded("index.fr.html", indexContent)
b.Build(BuildCfg{})
b.AssertFileContent("public/en/index.html", `
Hello1: Hello
Hello2: Hello
`)
b.AssertFileContent("public/fr/index.html", `
Hello1: Bonjour
Hello2: Bonjour
`)
}