Modularise templates

This commit is contained in:
Fred Boniface 2023-09-03 20:52:51 +01:00
parent dc7631ede2
commit d27625f112
3 changed files with 20 additions and 12 deletions

16
templates/base.html Normal file
View File

@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="charset" content="utf-8" />
<title>barcodes</title>
<!-- CSS and JS Inclusions -->
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="author" content="Frederick Boniface" />
<meta name="description" content="Easily create a variety of barcodes" />
</head>
<body>
<h1>{{ template "title" }}</h1>
{{ template "body" . }}
</body>
</html>

View File

@ -1,12 +1,5 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>API Documentation</title>
</head>
<body>
<h1>API Requests</h1>
{{ define "title" }}API Documentation{{ end }}
{{ define "body" }}
<p>API Requests can be made by making a POST request to /generate</p>
<p>The request body should be JSON similar to the below</p>
@ -37,5 +30,4 @@
<p><code>content</code> should be the value you wish the barcode to display. This should be a string and may not accept all characters - that is dependent on the barcode type.</p>
<p>The response will be a PNG image</p>
</body>
</html>
{{ end }}

View File

@ -22,7 +22,7 @@ func helpTemplate(w http.ResponseWriter, r *http.Request) {
BarcodeOptions: barcodeOptions,
}
tmpl := template.Must(template.New("help.html").ParseFiles("templates/help.html"))
tmpl := template.Must(template.New("base.html").ParseFiles("templates/base.html", "templates/help.html"))
err := tmpl.Execute(w, data)
if err != nil {