On Mon, Sep 3, 2012 at 9:58 AM, Yaşar Arabacı wrote:
Hi,
I have finished http://golang.org/doc/articles/wiki/ , and I am trying
add some things on it. I think I could put all templates inside tmpl/
and read whatever is there. I did this (unrelated parts omitted);
However, when I visit editing page, I get `html/template:
"tmpl/edit.html" is undefined`. What am I doing wrong here? Additional
comment is also welcome about how I use the language, as I am new and
trying to get used to it.
Hi,
I have finished http://golang.org/doc/articles/wiki/ , and I am trying
add some things on it. I think I could put all templates inside tmpl/
and read whatever is there. I did this (unrelated parts omitted);
However, when I visit editing page, I get `html/template:
"tmpl/edit.html" is undefined`. What am I doing wrong here? Additional
comment is also welcome about how I use the language, as I am new and
trying to get used to it.
should be executing "edit.html" not "tmpl/edit.html". Also,
filepath.Walk can make your code much simpler:
walk := func(path string, info os.FileInfo, err error) error {
if err == nil && !info.IsDir() && filepath.Ext(path) == ".html" {
// Load template
}
return err
}
err := filepath.Walk(root, walk)
- Max