diff --git a/templates.go b/templates.go
index 1501575..1c85c54 100644
--- a/templates.go
+++ b/templates.go
@@ -6,16 +6,43 @@ import (
"path/filepath"
"regexp"
"net/http"
+ "errors"
)
var (
templates = map[string]*template.Template{}
)
+// template helper function
+func dict (values ...interface{}) (map[string]interface{}, error) {
+ if len(values)%2 != 0 {
+ return nil, errors.New("invalid dict call")
+ }
+ dict := make(map[string]interface{}, len(values)/2)
+ for i := 0; i < len(values); i+=2 {
+ key, ok := values[i].(string)
+ if !ok {
+ return nil, errors.New("dict keys must be strings")
+ }
+ dict[key] = values[i+1]
+ }
+ return dict, nil
+}
+
+func stringTimes(times int, str string) string {
+ result := ""
+ for i := 0; i < times; i ++ {
+ result += str
+ }
+ return result
+}
+
// Tempalte helper functions
var funcMap = template.FuncMap {
"add": func (x, y int) int { return x + y },
"minus": func (x, y int) int { return x - y },
+ "dict": dict,
+ "stringTimes": stringTimes,
}
diff --git a/templates/pages/categories.html b/templates/pages/categories.html
index 7c2a1f1..e9d6d6d 100644
--- a/templates/pages/categories.html
+++ b/templates/pages/categories.html
@@ -1,48 +1,50 @@
{{define "body"}}
{{template "flashes" .}}
-
+
{{range $category := .categories}}
- {{template "row-category" $category}}
+ {{template "row-category" dict "category" $category "categories" $.categories}}
{{end}}
-
{{end}}
{{define "row-category"}}
- {{if .Parent.Valid }}
- {{with .Depth}}
-
-
- {{end}}
- {{else}}
-
- {{end}}
-
- {{.Name}}
delete
+
-
-
- {{range $child := .Children}}
- {{template "row-category" $child}}
+ {{range $child := .category.Children}}
+ {{template "row-category" dict "category" $child "categories" $.categories}}
{{end}}
{{end}}
{{define "option-category"}}
-
- {{range $child := .Children}}
- {{template "option-category" $child}}
+
+ {{range $child := .category.Children}}
+ {{template "option-category" dict "category" $child "id" $.id}}
{{end}}
-=======
->>>>>>> fea21c9d10d89f90b71988dcb41722527b947f60
{{end}}
\ No newline at end of file