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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, snippet := range snippets {
|
files := []string{
|
||||||
fmt.Fprintf(w, "%+v", snippet)
|
"./ui/html/base.tmpl",
|
||||||
|
"./ui/html/partials/nav.tmpl",
|
||||||
|
"./ui/html/pages/home.tmpl",
|
||||||
}
|
}
|
||||||
|
|
||||||
// files := []string{
|
ts, err := template.ParseFiles(files...)
|
||||||
// "./ui/html/base.tmpl",
|
if err != nil {
|
||||||
// "./ui/html/partials/nav.tmpl",
|
app.serverError(w, r, err)
|
||||||
// "./ui/html/pages/home.tmpl",
|
return
|
||||||
// }
|
}
|
||||||
|
|
||||||
// ts, err := template.ParseFiles(files...)
|
data := templateData{
|
||||||
// if err != nil {
|
Snippets: snippets,
|
||||||
// app.serverError(w, r, err)
|
}
|
||||||
// return
|
|
||||||
// }
|
|
||||||
|
|
||||||
// err = ts.ExecuteTemplate(w, "base", nil)
|
err = ts.ExecuteTemplate(w, "base", data)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// app.serverError(w, r, err)
|
app.serverError(w, r, err)
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// snippetView ...
|
// snippetView ...
|
||||||
|
@ -6,4 +6,5 @@ import (
|
|||||||
|
|
||||||
type templateData struct {
|
type templateData struct {
|
||||||
Snippet models.Snippet
|
Snippet models.Snippet
|
||||||
|
Snippets []models.Snippet
|
||||||
}
|
}
|
||||||
|
@ -2,5 +2,22 @@
|
|||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
<h2>Latest Snippets</h2>
|
<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}}
|
{{end}}
|
||||||
|
@ -1,16 +1,18 @@
|
|||||||
{{define "title"}}Snippet #{{.Snippet.ID}}{{end}}
|
{{define "title"}}Snippet #{{.Snippet.ID}}{{end}}
|
||||||
|
|
||||||
{{define "main"}}
|
{{define "main"}}
|
||||||
|
{{with .Snippet}}
|
||||||
<div class="snippet">
|
<div class="snippet">
|
||||||
<div class="metadata">
|
<div class="metadata">
|
||||||
<strong>{{.Snippet.Title}}</strong>
|
<strong>{{.Title}}</strong>
|
||||||
<span>#{{.Snippet.ID}}</span>
|
<span>#{{.ID}}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<pre><code>{{.Snippet.Content}}</code></pre>
|
<pre><code>{{.Content}}</code></pre>
|
||||||
<div class="metadata">
|
<div class="metadata">
|
||||||
<time>Created: {{.Snippet.Created}}</time>
|
<time>Created: {{.Created}}</time>
|
||||||
<time>Expires: {{.Snippet.Expires}}</time>
|
<time>Expires: {{.Expires}}</time>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{{end}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
Loading…
Reference in New Issue
Block a user