Of course it does not work. I have found an old post from 2016 that states that “it is not possible to go upwards in the chain. So layout.html gets rendered before home.html , so you cant pass a value back.”
But my question is - if someone figured out how to do this without using any Go code 2019?
BUT, as there are hundreds of templates with different titles, I want to move this to another go file:
main.go (simplifyed)
data := webtest.Title
layout.Execute(w, data)
title.go
package title
type Info struct{ Title, Content string }`
func Title() (title string) {
return (Info{"Your title page", "A classic lorem ipsum content"})
}
But as the return value is a “struct”? it gives an error:
cannot use Info literal (type Info) as type string in return argument