lets-go:5.2 home view
This commit is contained in:
parent
65c86f86d2
commit
0db8a9f74d
@ -23,26 +23,26 @@ func (app *application) home(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
for _, snippet := range snippets {
|
||||
fmt.Fprintf(w, "%+v", snippet)
|
||||
files := []string{
|
||||
"./ui/html/base.tmpl",
|
||||
"./ui/html/partials/nav.tmpl",
|
||||
"./ui/html/pages/home.tmpl",
|
||||
}
|
||||
|
||||
// files := []string{
|
||||
// "./ui/html/base.tmpl",
|
||||
// "./ui/html/partials/nav.tmpl",
|
||||
// "./ui/html/pages/home.tmpl",
|
||||
// }
|
||||
ts, err := template.ParseFiles(files...)
|
||||
if err != nil {
|
||||
app.serverError(w, r, err)
|
||||
return
|
||||
}
|
||||
|
||||
// ts, err := template.ParseFiles(files...)
|
||||
// if err != nil {
|
||||
// app.serverError(w, r, err)
|
||||
// return
|
||||
// }
|
||||
data := templateData{
|
||||
Snippets: snippets,
|
||||
}
|
||||
|
||||
// err = ts.ExecuteTemplate(w, "base", nil)
|
||||
// if err != nil {
|
||||
// app.serverError(w, r, err)
|
||||
// }
|
||||
err = ts.ExecuteTemplate(w, "base", data)
|
||||
if err != nil {
|
||||
app.serverError(w, r, err)
|
||||
}
|
||||
}
|
||||
|
||||
// snippetView ...
|
||||
|
@ -6,4 +6,5 @@ import (
|
||||
|
||||
type templateData struct {
|
||||
Snippet models.Snippet
|
||||
Snippets []models.Snippet
|
||||
}
|
||||
|
@ -2,5 +2,22 @@
|
||||
|
||||
{{define "main"}}
|
||||
<h2>Latest Snippets</h2>
|
||||
<p>leave me alone!</p>
|
||||
{{if .Snippets}}
|
||||
<table>
|
||||
<tr>
|
||||
<th>Title</th>
|
||||
<th>Created</th>
|
||||
<th>ID</th>
|
||||
</tr>
|
||||
{{range .Snippets}}
|
||||
<tr>
|
||||
<td><a href='/snippet/view?id={{.ID}}'>{{.Title}}</td>
|
||||
<td>{{.Created}}</td>
|
||||
<td>{{.ID}}</td>
|
||||
</tr>
|
||||
{{else}}
|
||||
<p>There's nothing to see here... yet!</p>
|
||||
{{end}}
|
||||
</table>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
@ -1,16 +1,18 @@
|
||||
{{define "title"}}Snippet #{{.Snippet.ID}}{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
{{with .Snippet}}
|
||||
<div class="snippet">
|
||||
<div class="metadata">
|
||||
<strong>{{.Snippet.Title}}</strong>
|
||||
<span>#{{.Snippet.ID}}</span>
|
||||
<strong>{{.Title}}</strong>
|
||||
<span>#{{.ID}}</span>
|
||||
</div>
|
||||
|
||||
<pre><code>{{.Snippet.Content}}</code></pre>
|
||||
<pre><code>{{.Content}}</code></pre>
|
||||
<div class="metadata">
|
||||
<time>Created: {{.Snippet.Created}}</time>
|
||||
<time>Expires: {{.Snippet.Expires}}</time>
|
||||
<time>Created: {{.Created}}</time>
|
||||
<time>Expires: {{.Expires}}</time>
|
||||
</div>
|
||||
</div>
|
||||
{{end}}
|
||||
{{end}}
|
||||
|
Loading…
Reference in New Issue
Block a user