doujiao7520 2017-06-27 06:52
浏览 82

pongo2 RegisterFilter如何返回映射或数组?

I need register a global filter to return userinfo from session. I resister a new filter.

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
}

and in the html i use like this:

{{ "getsess" | getSessions}}

but it's not work, the result is empty. but if reutrn a string is work well . if i want to return a map or array . how to do it ?

  • 写回答

1条回答 默认 最新

  • dongliyu3278 2017-06-27 09:26
    关注

    Use return in.Slice(start, limit), nil

    For example, This is implementation of limit filter can be used in for-loop.

    https://github.com/mattn/jedie/blob/0f3fb468befcb71b026f07b4158e121da8b6b0c5/helper.go#L120-L125

    评论

报告相同问题?