Merge branch 'main' of https://forge.happytavern.co/OceanSlim/GoStart
This commit is contained in:
commit
71ef8788e2
@ -1,14 +1,15 @@
|
|||||||
package routes
|
package routes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"GoStart/src/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ExampleHandler(w http.ResponseWriter, r *http.Request) {
|
func ExampleHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := PageData{
|
data := utils.PageData{
|
||||||
Title: "Example Page",
|
Title: "Example Page",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call renderTemplate with the specific template for this route
|
// Call RenderTemplate with the specific template for this route
|
||||||
renderTemplate(w, data, "example.html")
|
utils.RenderTemplate(w, data, "example.html")
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,13 @@
|
|||||||
package routes
|
package routes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"GoStart/src/utils"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RootHandler(w http.ResponseWriter, r *http.Request) {
|
func RootHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := PageData{
|
data := utils.PageData{
|
||||||
Title: "Home Page",
|
Title: "Home Page",
|
||||||
}
|
}
|
||||||
|
utils.RenderTemplate(w, data, "index.html")
|
||||||
// Call renderTemplate with the specific template for this route
|
|
||||||
renderTemplate(w, data, "index.html")
|
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
package routes
|
package utils
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"GoStart/src/utils"
|
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PageData struct {
|
type PageData struct {
|
||||||
Title string
|
Title string
|
||||||
|
Theme string
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define the base directories for views and templates
|
// Define the base directories for views and templates
|
||||||
@ -24,9 +24,9 @@ var templateFiles = []string{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the common templates with full paths
|
// 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
|
// Append the specific template for the route
|
||||||
templates := append(layout, viewsDir+view)
|
templates := append(layout, viewsDir+view)
|
@ -1,6 +1,6 @@
|
|||||||
{{define "layout"}}
|
{{define "layout"}}
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en" data-theme="">
|
<html lang="en" data-theme="{{.Theme}}">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
|
Loading…
Reference in New Issue
Block a user