Browse Source

Added render template function to index handler

Wirecog 7 years ago
parent
commit
6ad01e592d
1 changed files with 13 additions and 3 deletions
  1. 13
    3
      handlers/index.go

+ 13
- 3
handlers/index.go View File

@@ -1,12 +1,22 @@
1 1
 package handlers
2 2
 
3 3
 import (
4
+	"html/template"
5
+	"log"
4 6
 	"net/http"
5 7
 	"os"
6
-
7
-	"github.com/isomorphicgo/isogoapp/view"
8 8
 )
9 9
 
10
+// Template rendering function
11
+func RenderTemplate(w http.ResponseWriter, templateFile string, templateData interface{}) {
12
+
13
+	t, err := template.ParseFiles(templateFile)
14
+	if err != nil {
15
+		log.Fatal("Error encountered while parsing the template: ", err)
16
+	}
17
+	t.Execute(w, templateData)
18
+}
19
+
10 20
 func IndexHandler(w http.ResponseWriter, r *http.Request) {
11
-	view.RenderTemplate(w, os.Getenv("ISOGO_APP_ROOT")+"/templates/index.tmpl", nil)
21
+	RenderTemplate(w, os.Getenv("ISOGO_APP_ROOT")+"/templates/index.tmpl", nil)
12 22
 }