LoginSignup
1
0

More than 3 years have passed since last update.

template.ParseFilesの省略

Last updated at Posted at 2020-01-20

自分用に、いちいちtemplateを呼び出すときに2,3行かくのめんどいので1行で書こうとした。

func handleIndex(w http.ResponseWriter, r *http.Request) {
    v := 1
    render("index").Execute(w, v) 

//t :=template.ParseFiles("index")  t.Execute(w, v) を省略した。()の中身を変えるだけでfileが呼び出せる。
//変更するのは()の引数とvの値のみでOK!!わざわざtemplate.Parsefile書くのめんどかった。
}
func render(name string) *template.Template {
    t, _ := template.ParseFiles(name + ".html")
    return t
}
//引数にfile名を指定し活用
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0