{{.Variable}} doesn't work in included blocks
rdbell opened this issue · comments
Hi,
I have a file, layout.ace, that looks like this:
html
head
body
= include header
= yield main
= include footer
I'm calling layout.ace like this...
func index(res http.ResponseWriter, req *http.Request, user *userSchema) {
tpl, err := aceProxy.Load("layout", "index", nil)
if err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
}
data := map[string]interface{}{
"Title": "Example Title",
"User": user,
}
if err := tpl.Execute(res, data); err != nil {
http.Error(res, err.Error(), http.StatusInternalServerError)
return
}
}
Now in my layout.ace and index.ace files, I can refererence values in my data map by using {{.Title}}
or {{.User.Email}}
but if I try to use those statements in my header.ace file they are empty.
Is this intended behavior? Is there some way I can reference values in my data map from = include
blocks such as my header/footer?
Is there some way I can reference values in my data map from = include blocks such as my header/footer?
Hi, thanks for your comment.
Could you try = include header .
and = include footer .
instead of = include header
and = include footer
?
Thanks! This works fine.
I see I can also use = include header .User
and then reference {{.Email}}
to access the User.Email value in the same way.
Outside of ace, I haven't worked with Go's text/template package before, so pipelines were unfamiliar to me.
The Ace Syntax document makes more sense to me now.
Thanks Keiji.
Is possible to call a $.Func
of $.Var
in addition to the current pipeline .
from an included template (I'm inside a range)? I don't see how to pass the pipeline and the global context. Thanks!