diff --git a/main.go b/main.go index c2ee44f..5f8c232 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ import ( Controllers "micrach/controllers" Db "micrach/db" Repositories "micrach/repositories" + Templates "micrach/templates" Utils "micrach/utils" ) @@ -51,14 +52,8 @@ func main() { router.Use(gin.Recovery()) router.SetFuncMap(template.FuncMap{ - "Iterate": func(count int) []int { - var i int - var Items []int - for i = 1; i < count+1; i++ { - Items = append(Items, i) - } - return Items - }, + "Iterate": Templates.Iterate, + "NotNil": Templates.NotNil, }) router.LoadHTMLGlob("templates/**/*") router.ForwardedByClientIP = true diff --git a/templates/components/header.html b/templates/components/header.html index c8d78db..67cb1ef 100644 --- a/templates/components/header.html +++ b/templates/components/header.html @@ -1,6 +1,6 @@ {{ define "header" }} -{{ if . }} +{{ if NotNil . }}

{{ if ne . "" }} diff --git a/templates/templates.go b/templates/templates.go new file mode 100644 index 0000000..af6dedc --- /dev/null +++ b/templates/templates.go @@ -0,0 +1,16 @@ +package templates + +// Generates a slice of numbers +func Iterate(count int) []int { + var i int + var Items []int + for i = 1; i < count+1; i++ { + Items = append(Items, i) + } + return Items +} + +// Checks if the value is not nil +func NotNil(v interface{}) bool { + return v != nil +}