1
0
Fork 0
mirror of https://github.com/Luzifer/mondash.git synced 2024-12-23 12:31:18 +00:00
mondash/filters/filter.go

21 lines
366 B
Go
Raw Normal View History

package filters
import "github.com/flosch/pongo2"
func init() {
pongo2.RegisterFilter("lastNItems", filterLastNItems)
}
func filterLastNItems(in *pongo2.Value, param *pongo2.Value) (*pongo2.Value, *pongo2.Error) {
if !in.CanSlice() {
return in, nil
}
from := in.Len() - param.Integer()
if from < 0 {
from = 0
}
return in.Slice(from, in.Len()), nil
}