嵌套模板未显示

时间:2018-06-03 22:06:43

标签: go

我试图让嵌套模板在Go中运行(我是新手),但到目前为止它还没有加载任何东西,我已经查看了很多教程来实现这一点,而且他们都做了和我一样。

package routes

import (
    "html/template"
    "net/http"
)

func homePage(w http.ResponseWriter, r *http.Request) {
    t, _ := template.ParseFiles("skins/default/skeleton/index.html")
    t.ExecuteTemplate(w, "skeleton", "")
}

func newAccount(w http.ResponseWriter, r *http.Request) {
    var t *template.Template

    t, _ = template.ParseFiles("skins/default/skeleton/index.html", "skins/default/accounts/new.html")

    t.ExecuteTemplate(w, "skeleton", "")
}

func Routing() {
    http.HandleFunc("/", homePage)
    http.HandleFunc("/accounts/new", newAccount)
}

骨架/ index.html中:

{{ define "skeleton" }}
<!DOCTYPE html>
<html>
<head>
<title>My Page</title>
</head>
<body>
{{ template "accounts/new" }}
</body>
</html>
{{ end }}

帐户/ new.html:

{{ define "accounts/new" }}
Hello world
{{ end }}

当我转到每个网址时,骨架或accounts / new.html都没有呈现。为什么不起作用?

0 个答案:

没有答案