gofiber/template

Render not pass variable if set fiber.Map

Closed this issue ยท 8 comments

I am use Jet template

This not work:

		err := c.Render("index", fiber.Map{
			"qwe": "Hello, World ๐Ÿ‘‹!",
		})

This work:

		err := c.Render("index", map[string]interface{}{
			"qwe": "Hello, World ๐Ÿ‘‹!",
		})

because in func jetVarMap

template/jet/jet.go

Lines 211 to 225 in d8ce3c2

func jetVarMap(binding interface{}) jet.VarMap {
var bind jet.VarMap
if binding == nil {
return bind
}
if binds, ok := binding.(map[string]interface{}); ok {
bind = make(jet.VarMap)
for key, value := range binds {
bind.Set(key, value)
}
} else if binds, ok := binding.(jet.VarMap); ok {
bind = binds
}
return bind
}

doesn't check type fiber.Map so we can fix with:

if binds, ok := binding.(fiber.Map); ok {
//do something
}

but it must import pkg "github.com/gofiber/fiber"

or we can fix it in:
convert bind to map[string]interface
https://github.com/gofiber/fiber/blob/b5645f8f21b159120f4c84dfefe8b5b2327cc5c5/ctx.go#L770

Fenny commented

That would do the trick, I can accept a PR with this fix ๐Ÿ‘

Fenny commented

Fixed in #27

@Fenny , another template need this patch too

Fenny commented

@fuadarradhi, which one?

Fenny commented

I will do some testing

Fenny commented

Should be fixed in https://github.com/gofiber/template/releases/tag/v1.5.5 thnx for the report ๐Ÿ‘