updates, sort interface
This commit is contained in:
14
page/page.go
14
page/page.go
@@ -20,8 +20,9 @@ var funcMap = template.FuncMap{
|
||||
|
||||
// Page type
|
||||
type Page struct {
|
||||
Name string
|
||||
Body interface{}
|
||||
Name string
|
||||
Class string
|
||||
Body interface{}
|
||||
}
|
||||
|
||||
// Render the page
|
||||
@@ -37,7 +38,11 @@ func (p *Page) Render(w http.ResponseWriter, r *http.Request, templates ...strin
|
||||
return 200, nil
|
||||
}
|
||||
|
||||
// GetTemplate is used to get a ready to use template based on the url and on
|
||||
// other sent templates
|
||||
func GetTemplate(r *http.Request, templates ...string) (*template.Template, error) {
|
||||
// If this is a pjax request, use the minimal template to send only
|
||||
// the main content
|
||||
if r.Header.Get("X-PJAX") == "true" {
|
||||
templates = append(templates, "base_minimal")
|
||||
} else {
|
||||
@@ -46,14 +51,19 @@ func GetTemplate(r *http.Request, templates ...string) (*template.Template, erro
|
||||
|
||||
var tpl *template.Template
|
||||
|
||||
// For each template, add it to the the tpl variable
|
||||
for i, t := range templates {
|
||||
// Get the template from the assets
|
||||
page, err := assets.Asset("templates/" + t + templateExtension)
|
||||
|
||||
// Check if there is some error. If so, the template doesn't exist
|
||||
if err != nil {
|
||||
log.Print(err)
|
||||
return new(template.Template), err
|
||||
}
|
||||
|
||||
// If it's the first iteration, creates a new template and add the
|
||||
// functions map
|
||||
if i == 0 {
|
||||
tpl, err = template.New(t).Funcs(funcMap).Parse(string(page))
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user