mirror of
https://github.com/yanislav-igonin/micrach
synced 2024-12-22 14:22: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"
|
Controllers "micrach/controllers"
|
||||||
Db "micrach/db"
|
Db "micrach/db"
|
||||||
Repositories "micrach/repositories"
|
Repositories "micrach/repositories"
|
||||||
|
Templates "micrach/templates"
|
||||||
Utils "micrach/utils"
|
Utils "micrach/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -51,14 +52,8 @@ func main() {
|
|||||||
router.Use(gin.Recovery())
|
router.Use(gin.Recovery())
|
||||||
|
|
||||||
router.SetFuncMap(template.FuncMap{
|
router.SetFuncMap(template.FuncMap{
|
||||||
"Iterate": func(count int) []int {
|
"Iterate": Templates.Iterate,
|
||||||
var i int
|
"NotNil": Templates.NotNil,
|
||||||
var Items []int
|
|
||||||
for i = 1; i < count+1; i++ {
|
|
||||||
Items = append(Items, i)
|
|
||||||
}
|
|
||||||
return Items
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
router.LoadHTMLGlob("templates/**/*")
|
router.LoadHTMLGlob("templates/**/*")
|
||||||
router.ForwardedByClientIP = true
|
router.ForwardedByClientIP = true
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{{ define "header" }}
|
{{ define "header" }}
|
||||||
|
|
||||||
{{ if . }}
|
{{ if NotNil . }}
|
||||||
<a href="/" class="thread-title-link">
|
<a href="/" class="thread-title-link">
|
||||||
<h1 class="display-1 text-center thread-title">
|
<h1 class="display-1 text-center thread-title">
|
||||||
{{ if ne . "" }}
|
{{ 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