API Example
- Access Example API -Content Section
-- This is the main content of your web app. You can add any HTML content - here. -
- Another Example Route can be found here -diff --git a/.gitignore copy b/.gitignore copy new file mode 100644 index 0000000..05988f2 --- /dev/null +++ b/.gitignore copy @@ -0,0 +1,2 @@ +output.css +config.json \ No newline at end of file diff --git a/src/routes/example.go b/src/routes/example.go index 742b46f..c4b4987 100644 --- a/src/routes/example.go +++ b/src/routes/example.go @@ -1,7 +1,23 @@ package routes -import "net/http" +import ( + "html/template" + "net/http" +) func ExampleHandler(w http.ResponseWriter, r *http.Request) { - http.ServeFile(w, r, "web/views/example.html") + data := PageData{ + Title: "Example Page", + } + + tmpl, err := template.ParseFiles("web/views/.layout.html", "web/views/example.html") + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + return + } + + err = tmpl.ExecuteTemplate(w, "layout", data) + if err != nil { + http.Error(w, err.Error(), http.StatusInternalServerError) + } } \ No newline at end of file diff --git a/src/routes/root.go b/src/routes/root.go index a6be1ea..e9cd9be 100644 --- a/src/routes/root.go +++ b/src/routes/root.go @@ -14,14 +14,14 @@ func RootHandler(w http.ResponseWriter, r *http.Request) { Title: "Home Page", } - tmpl, err := template.ParseFiles("web/views/index.html") + tmpl, err := template.ParseFiles("web/views/.layout.html", "web/views/index.html") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } - err = tmpl.Execute(w, data) + err = tmpl.ExecuteTemplate(w, "layout", data) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } -} \ No newline at end of file +} diff --git a/web/views/.layout.html b/web/views/.layout.html new file mode 100644 index 0000000..8490629 --- /dev/null +++ b/web/views/.layout.html @@ -0,0 +1,16 @@ +{{define "layout"}} + + +
+ + +- This is the main content of your web app. You can add any HTML content - here. -
- Another Example Route can be found here -+ This is the main content of your web app. You can add any HTML content + here. +
+ Another Example Route can be found here +