ch13.1
This commit is contained in:
@@ -2,11 +2,13 @@ package main
|
||||
|
||||
import (
|
||||
"html/template"
|
||||
"io/fs"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"gitea.local.lab/Lbenedar/snippetbox/internal/models"
|
||||
"gitea.local.lab/Lbenedar/snippetbox/ui"
|
||||
"github.com/justinas/nosurf"
|
||||
)
|
||||
|
||||
@@ -40,24 +42,20 @@ func (app *application) newTemplateData(r *http.Request) *templateData {
|
||||
func newTemplateCache() (map[string]*template.Template, error) {
|
||||
cache := map[string]*template.Template{}
|
||||
|
||||
pages, err := filepath.Glob("./ui/html/pages/*.tmpl")
|
||||
pages, err := fs.Glob(ui.Files, "html/pages/*.tmpl")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, page := range pages {
|
||||
name := filepath.Base(page)
|
||||
ts, err := template.New(name).Funcs(functions).ParseFiles("./ui/html/base.tmpl")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ts, err = ts.ParseGlob("./ui/html/partials/nav.tmpl")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
patterns := []string{
|
||||
"html/base.tmpl",
|
||||
"html/partials/*.tmpl",
|
||||
page,
|
||||
}
|
||||
|
||||
ts, err = ts.ParseFiles(page)
|
||||
ts, err := template.New(name).Funcs(functions).ParseFS(ui.Files, patterns...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user