mirror of
https://github.com/yanislav-igonin/micrach
synced 2024-12-22 06:12:33 +03:00
feat: separate templates package, now header has link even with empty title
This commit is contained in:
parent
f7be64e1b4
commit
140d56b627
11
main.go
11
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
|
||||
|
@ -1,6 +1,6 @@
|
||||
{{ define "header" }}
|
||||
|
||||
{{ if . }}
|
||||
{{ if NotNil . }}
|
||||
<a href="/" class="thread-title-link">
|
||||
<h1 class="display-1 text-center thread-title">
|
||||
{{ if ne . "" }}
|
||||
|
16
templates/templates.go
Normal file
16
templates/templates.go
Normal file
@ -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
|
||||
}
|
Loading…
Reference in New Issue
Block a user