lets-go:2.7 nav
This commit is contained in:
parent
728dd501c7
commit
9baa1ac716
@ -2,6 +2,8 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
@ -12,7 +14,26 @@ func home(w http.ResponseWriter, r *http.Request) {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
w.Write([]byte("Hello from snippetbox.chaosfem.tw"))
|
||||
|
||||
files := []string{
|
||||
"./ui/html/base.tmpl",
|
||||
"./ui/html/partials/nav.tmpl",
|
||||
"./ui/html/pages/home.tmpl",
|
||||
}
|
||||
|
||||
ts, err := template.ParseFiles(files...)
|
||||
if err != nil {
|
||||
log.Print(err.Error())
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
err = ts.ExecuteTemplate(w, "base", nil)
|
||||
if err != nil {
|
||||
log.Print(err.Error())
|
||||
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// snippetView ...
|
||||
|
19
snippetbox/ui/html/base.tmpl
Normal file
19
snippetbox/ui/html/base.tmpl
Normal file
@ -0,0 +1,19 @@
|
||||
{{define "base"}}
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>{{template "title" .}} - Snippetbox</title>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1><a href="/">Snippetbox</a></h1>
|
||||
</header>
|
||||
{{template "nav" .}}
|
||||
<main>
|
||||
{{template "main" .}}
|
||||
</main>
|
||||
<footer>Powered by <a href="https://golang.org">Go</a></footer>
|
||||
</body>
|
||||
</html>
|
||||
{{end}}
|
@ -1,17 +1,6 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Home - Snippetbox</title>
|
||||
</head>
|
||||
<body>
|
||||
<header>
|
||||
<h1><a href="/">Snippetbox</a></h1>
|
||||
</header>
|
||||
<main>
|
||||
{{define "title"}}Home{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
<h2>Latest Snippets</h2>
|
||||
<p>leave me alone!</p>
|
||||
</main>
|
||||
<footer>Powered by <a href="https://golang.org">Go</a></footer>
|
||||
</body>
|
||||
</html>
|
||||
{{end}}
|
||||
|
5
snippetbox/ui/html/partials/nav.tmpl
Normal file
5
snippetbox/ui/html/partials/nav.tmpl
Normal file
@ -0,0 +1,5 @@
|
||||
{{define "nav"}}
|
||||
<nav>
|
||||
<a href="/">Home</a>
|
||||
</nav>
|
||||
{{end}}
|
Loading…
Reference in New Issue
Block a user