我需要注册一个全局过滤器来从会话中返回userinfo。我抵制了一种新的过滤器。
pongo2.RegisterFilter("getSessions", getSession)
func getSession(in, param *pongo2.Value) (*pongo2.Value,*pongo2.Error) {
uInfo := lib.Sess.Get("userInfo")
if uInfo == nil {
lib.Logs.Error("get userinfo err from session")
} else {
}
return pongo2.AsValue(uInfo), nil
}在我使用的html中,如下所示:
{{ "getsess" | getSessions}}但这不是功,结果是空的。但如果反串就能很好地工作。如果我想返回一个映射或数组。该怎么做呢?
发布于 2017-06-27 17:26:11
使用return in.Slice(start, limit), nil
例如,这是limit滤波器的实现,可以在For循环中使用。
https://github.com/mattn/jedie/blob/0f3fb468befcb71b026f07b4158e121da8b6b0c5/helper.go#L120-L125
https://stackoverflow.com/questions/44773933
复制相似问题