title: Pass a string to template in golang
body: <p>I've been scouring the internet and can't find much at all about posting to html template and form in golang . This is my attempt at it</p>
  
  <p><strong>my error</strong>
  cannot use "html/template".HTML("
  login") (type "html/template".HTML) as type string in argument to "html/template
  ".New("foo").Parse</p>
  
  <p>i want to pass a value to {{.ErrorMessage}} in html file</p>
  
  <p>My HTML (login.html)</p>
  
  <pre><code>{{ define "content"}}
  &lt;h2&gt; {{.ErrorMessage}}&lt;/h2&gt;
  
  
  form action="/login" method="POST"&gt;
  Username:input type="username" name="username"&gt;
  Password:input type="password" name="password"&gt;
  input type="submit" value="Submit"&gt;
  /form&gt;
  
  {{end}}
  
  {{define "extra_head"}} &lt;title&gt;Title&lt;/title&gt;{{end}}
  {{define "nav"}}{{end}}
  
  
  {{define "extra_footer"}}&lt;footer&gt;copyright@xyz.com&lt;/footer&gt;{{end}}
  {{template "_layout.html" .}}
  </code></pre>
  
  <p><strong>MAIN.G0</strong></p>
  
  <pre><code>package main
  
  import (
  
  "net/http"
  "ere.com/handlers"
  )
  
  func main() {
  http.HandleFunc("/register", handlers.RegisterHandler) // setting router rule
  http.HandleFunc("/sucess", handlers.RegisterSucessHandler)
  http.HandleFunc("/login", handlers.LoginHandler)
  http.HandleFunc("/update", handlers.UpdateHandler)
  http.HandleFunc("/logout", handlers.LogoutHandler)
  http.HandleFunc("/header", handlers.HeaderHandler)
  
  
  if err := http.ListenAndServe(":8181", nil); err != nil {
      //log.Fatal("http.ListenAndServe: ", err)
  }
  
  
  }
  </code></pre>
  
  <p><strong>handler int</strong></p>
  
  <pre><code>    package handlers
        import (
        "html/template"
         )
  
  func GetTemplate(name string) *template.Template{
  tmpl := template.Must(template.ParseFiles(
      "frontend/templates/_layout.html",
      "frontend/templates/" + name + ".html",
  ))
  
  
  return tmpl
  }
  </code></pre>
  
  <p><strong>LoginHandler</strong></p>
  
  <pre><code>    type viewModel    struct {
  Id          bson.ObjectId
  Email       string
  Password    string
  FirstName   string
  LastName    string
  ErrorMessage    string
  }
      func LoginHandler (response http.ResponseWriter, request *http.Request) {
  viewModel:=viewmodels.RegisterViewModel{}
  
  if (request.Method == "POST") {
  
      request.ParseForm()
      user := models.User{}
      user.Email = request.Form.Get("username")
      user.Password = request.Form.Get("password")
      boolUser, userID := user.FindUserDB()
  
      if (boolUser != true) {
  
          viewModel.ErrorMessage = "incorrect username or password"
  
        //need help here
  
          t, err := template.New("foo").Parse(template.HTML("login"))
          err = t.ExecuteTemplate(response, "T", viewModel)
  
  
          err := GetTemplate("login").Execute(response, nil, )
  
          if err != nil {
              panic(err)
          }
  
      }else {
  
          setSession(userID, response)
          http.Redirect(response, request, "/update", 302)
      }
  
  
  }else {
      err := GetTemplate("login").Execute(response, nil,)
  
      if err != nil {
          panic(err)
      }
  
  }
  </code></pre>