add base/footer/header templates and use them on home route

This commit is contained in:
lyx0 2024-02-11 19:18:40 +01:00
parent 743cc82a87
commit 65e760454c
5 changed files with 35 additions and 12 deletions

View file

@ -167,7 +167,13 @@ type homeRouteData struct {
}
func (app *application) homeRoute(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
t, err := template.ParseFiles("./web/templates/home.page.gohtml")
t, err := template.ParseFiles(
"./web/templates/base.template.gohtml",
"./web/templates/header.partial.gohtml",
"./web/templates/footer.partial.gohtml",
"./web/templates/home.page.gohtml",
)
if err != nil {
app.Log.Error(err)
return

View file

@ -0,0 +1,18 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width,initial-scale=1" name="viewport">
<title>{{ template "title" . }}</title>
<meta property="og:title" content="nourybot - lidl twitch bot">
<meta property="og:description" content="nourybot">
</head>
<header>
{{ template "header" .}}
</header>
<body>
{{ template "body" . }}
</body>
<footer>
{{ template "footer" . }}
</footer>

View file

@ -0,0 +1,3 @@
{{define "footer"}}
Powered by <a href="https://go.dev/">Go</a>
{{end}}

View file

@ -0,0 +1,3 @@
{{define "header"}}
<h1><a href='/'>nourybot</a></h1>
{{end}}

View file

@ -1,13 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta content="width=device-width,initial-scale=1" name="viewport">
<title>nourybot - lidl twitch bot</title>
<meta property="og:title" content="nourybot - lidl twitch bot">
<meta property="og:description" content="nourybot">
</head>
<h1>nourybot</h1>
{{define "title"}}nourybot{{end}}
{{define "body"}}
<p>Channels connected to:</hp>
<table>
<tr>
@ -21,5 +13,6 @@
<td>{{ .Login }}</td>
</tr>
{{ end }}
{{ end }}
</table>
{{end}}