1
0
Fork 0
mirror of https://github.com/Luzifer/mondash.git synced 2024-11-13 01:42:41 +00:00
mondash/filters/filter.go
Knut Ahlers 91b4e1a21c Display only 60 items in graph
The decision is left to the template so template designers can easily change this behavior by removing the lastNItems filter in the template itself. Also the value can be changed easily.

fixes #4
2015-07-10 20:28:55 +02:00

16 lines
336 B
Go

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()
return in.Slice(from, in.Len()), nil
}