You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
package main
import (
"fmt""html/template""io/ioutil""log""path""strings"
)
typeAstruct {
I []string
}
funcmain() {
fori, tpl:=rangetpls {
t, err:=template.New("foo").Funcs(funcs).Parse(tpl)
iferr!=nil {
log.Fatal(err)
}
a:=A{I: []string{"abc"}}
err=t.Execute(ioutil.Discard, a)
iferr!=nil {
fmt.Printf("%d failed: %s\n", i, err)
}
}
}
vartpls= []string{
// Without surrounding div executes OK`{{ range .I }}{{ if in . "a" }}{{ join . "a.jpg" }}{{ else }}a.jpg{{ end }}{{ end }}`,
// This also works fine`<div style="background: url({{ range .I }}{{ if in . "a" }}ab.jpg{{ else }}a.jpg{{ end }}{{ end }})">FOO</div>`,
// This fails`<div style="background: url({{ range .I }}{{ if in . "a" }}{{ join . "a.jpg" }}{{ else }}a.jpg{{ end }}{{ end }})">FOO</div>`,
}
varfuncs=map[string]interface{}{
"join": func(a, bstring) string { returnpath.Join(a, b) },
"in": func(a, bstring) bool { returnstrings.Contains(a, b) },
}
The above prints:
2 failed: html/template:foo:1:62: on range loop re-entry: {{join . "a.jpg"}} appears in an ambiguous URL context
I would have expected it to not error.
The text was updated successfully, but these errors were encountered:
rsc
changed the title
html/template: on range loop re-entry: appears in an ambiguous URL context
html/template: clarify "ambiguous URL context" message
Oct 19, 2016
The above prints:
I would have expected it to not error.
The text was updated successfully, but these errors were encountered: