header seperated from view

This commit is contained in:
X201 2024-05-26 20:38:49 -04:00
parent 157729db16
commit 55c6a35042
4 changed files with 9 additions and 7 deletions

View File

@ -14,7 +14,7 @@ func RootHandler(w http.ResponseWriter, r *http.Request) {
Title: "Home Page",
}
tmpl, err := template.ParseFiles("web/views/#layout.html", "web/views/index.html")
tmpl, err := template.ParseFiles("web/views/#layout.html", "web/views/index.html", "web/views/#header.html")
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return

7
web/views/#header.html Normal file
View File

@ -0,0 +1,7 @@
{{define "header"}}
<header>
<h1 class="mt-8 mb-8 text-3xl font-bold text-blue-400">
Welcome to My GO Web App Framework {{.Title}}
</h1>
</header>
{{end}}

View File

@ -10,6 +10,7 @@
<script src="/static/htmx.min.js"></script>
</head>
<body class="text-center text-blue-300 bg-gray-800">
{{template "header" .}}
{{template "view" .}}
</body>
</html>

View File

@ -1,10 +1,4 @@
{{define "view"}}
<header>
<h1 class="mt-8 mb-8 text-3xl font-bold text-blue-400">
Welcome to My GO Web App Framework {{.Title}}
</h1>
</header>
<main>
<section>
<button hx-get="/api/example" class="p-2 text-white bg-blue-400 rounded-md">