hugolib: Add a test for template variable overwrite

New in Go 1.11.
This commit is contained in:
Bjørn Erik Pedersen 2018-08-28 17:35:33 +02:00
parent f4675fa0f0
commit 0c8a415483
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F

View file

@ -259,13 +259,17 @@ T2: Content: {{ $combinedText.Content }}|{{ $combinedText.RelPermalink }}
}}, }},
{"execute-as-template", func() bool { return true }, func(b *sitesBuilder) { {"execute-as-template", func() bool { return true }, func(b *sitesBuilder) {
b.WithTemplates("home.html", ` b.WithTemplates("home.html", `
{{ $var := "Hugo Page" }}
{{ if .IsHome }}
{{ $var = "Hugo Home" }}
{{ end }}
T1: {{ $var }}
{{ $result := "{{ .Kind | upper }}" | resources.FromString "mytpl.txt" | resources.ExecuteAsTemplate "result.txt" . }} {{ $result := "{{ .Kind | upper }}" | resources.FromString "mytpl.txt" | resources.ExecuteAsTemplate "result.txt" . }}
T1: {{ $result.Content }}|{{ $result.RelPermalink}}|{{$result.MediaType.Type }} T2: {{ $result.Content }}|{{ $result.RelPermalink}}|{{$result.MediaType.Type }}
`) `)
}, func(b *sitesBuilder) { }, func(b *sitesBuilder) {
b.AssertFileContent("public/index.html", `T1: HOME|/result.txt|text/plain`) b.AssertFileContent("public/index.html", `T2: HOME|/result.txt|text/plain`, `T1: Hugo Home`)
}}, }},
{"fingerprint", func() bool { return true }, func(b *sitesBuilder) { {"fingerprint", func() bool { return true }, func(b *sitesBuilder) {