example page fixed

This commit is contained in:
Chris kerr 2024-05-27 20:55:30 -04:00
parent 9f741eecbe
commit c0b4e92a57
2 changed files with 18 additions and 24 deletions

View File

@ -7,17 +7,17 @@ import (
func ExampleHandler(w http.ResponseWriter, r *http.Request) {
data := PageData{
Title: "Example Page",
}
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
}
tmpl, err := template.ParseFiles("web/views/#layout.html", "web/views/example.html", "web/views/#header.html", "web/views/#footer.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)
}
err = tmpl.ExecuteTemplate(w, "layout", data)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
}

View File

@ -1,17 +1,11 @@
{{define "view"}}
<header>
<h1 class="mt-8 mb-8 text-3xl font-bold text-blue-300">
This is an additional example route
</h1>
</header>
<main>
<section>
<h1 class="font-bold">Serve Static Files Like this Globe</h1>
<h1 class="font-bold">Serve Static Files Like this Gopher</h1>
<button hx-get="/" class="p-2 text-white bg-blue-400 rounded-md">
Click Me!
</button>
<img src="/static/img/gopher.png" alt="alternate text">
</main>
<footer>
<p>&copy; 2024 My Web App</p>
</footer>
{{end}}