diff --git a/src/routes/example.go b/src/routes/example.go index f04f1dd..35f21fb 100644 --- a/src/routes/example.go +++ b/src/routes/example.go @@ -1,14 +1,15 @@ package routes import ( + "GoStart/src/utils" "net/http" ) func ExampleHandler(w http.ResponseWriter, r *http.Request) { - data := PageData{ + data := utils.PageData{ Title: "Example Page", } - // Call renderTemplate with the specific template for this route - renderTemplate(w, data, "example.html") + // Call RenderTemplate with the specific template for this route + utils.RenderTemplate(w, data, "example.html") } diff --git a/src/routes/root.go b/src/routes/root.go index c823931..b75166e 100644 --- a/src/routes/root.go +++ b/src/routes/root.go @@ -1,14 +1,13 @@ package routes import ( + "GoStart/src/utils" "net/http" ) func RootHandler(w http.ResponseWriter, r *http.Request) { - data := PageData{ + data := utils.PageData{ Title: "Home Page", } - - // Call renderTemplate with the specific template for this route - renderTemplate(w, data, "index.html") + utils.RenderTemplate(w, data, "index.html") } diff --git a/src/routes/template.go b/src/utils/template.go similarity index 83% rename from src/routes/template.go rename to src/utils/template.go index 5997e10..9e064c6 100644 --- a/src/routes/template.go +++ b/src/utils/template.go @@ -1,13 +1,13 @@ -package routes +package utils import ( - "GoStart/src/utils" "html/template" "net/http" ) type PageData struct { Title string + Theme string } // Define the base directories for views and templates @@ -24,9 +24,9 @@ var templateFiles = []string{ } // Initialize the common templates with full paths -var layout = utils.PrependDir(templatesDir, templateFiles) +var layout = PrependDir(templatesDir, templateFiles) -func renderTemplate(w http.ResponseWriter, data PageData, view string) { +func RenderTemplate(w http.ResponseWriter, data PageData, view string) { // Append the specific template for the route templates := append(layout, viewsDir+view) diff --git a/web/views/templates/#layout.html b/web/views/templates/#layout.html index c595310..318b573 100644 --- a/web/views/templates/#layout.html +++ b/web/views/templates/#layout.html @@ -1,6 +1,6 @@ {{define "layout"}} - +