我尝试将马提尼框架与布局模板一起使用:
package main
import (
"github.com/go-martini/martini"
"github.com/martini-contrib/render"
)
func main() {
m := martini.Classic()
m.Use(render.Renderer(render.Options{Directory: "./templates",
Layout: "layout",
Extensions: []string{".tmpl"},
}))
m.Get("/", func(r render.Render) {
r.HTML(200, "mainPage", map[string]interface{}{"Title": "some title", "H1": "some h1"})
})
m.Run()
}
在与此main.go 文件相同的文件夹中,我得到了templates包含layout.tmpl文件的文件夹:
<html xmlns="http://www.w3.org/1999/xhtml"></html>
<head></head>
<body>
<div id='left'>
{{template "left" .}}
</div>
<div id='right'>
{{template "right" .}}
</div>
</body>
和mainPage.tmpl文件:
{{define "left"}}
left content
{{end}}
{{define "right"}}
right content
{{end}}
当我http://localhost:3000/在浏览器中打开时,我看到错误: html/template: "layout" is undefined
慕哥6287543
相关分类