summaryrefslogtreecommitdiffstats
path: root/tpl/collections/sort.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-06-09 12:50:53 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2019-06-10 08:32:44 +0200
commite8a716b23a1ca78cf29460daacd4ba49bbc05ad1 (patch)
treea55a3ade6ca19306b3ebbae6cbafd2aefaa4c880 /tpl/collections/sort.go
parent3e6cb2cb77e16be5b6ddd4ae55d5fc6bfba2d226 (diff)
tpl/collections: Fix slice type handling in sort
The `sort` template func was producing a `[]page.Page` which did not work in `.Paginate`. Fixes #6023
Diffstat (limited to 'tpl/collections/sort.go')
-rw-r--r--tpl/collections/sort.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/tpl/collections/sort.go b/tpl/collections/sort.go
index 206a19cb5..1ab4409b6 100644
--- a/tpl/collections/sort.go
+++ b/tpl/collections/sort.go
@@ -31,21 +31,23 @@ func (ns *Namespace) Sort(seq interface{}, args ...interface{}) (interface{}, er
return nil, errors.New("sequence must be provided")
}
- seqv := reflect.ValueOf(seq)
- seqv, isNil := indirect(seqv)
+ seqv, isNil := indirect(reflect.ValueOf(seq))
if isNil {
return nil, errors.New("can't iterate over a nil value")
}
+ var sliceType reflect.Type
switch seqv.Kind() {
- case reflect.Array, reflect.Slice, reflect.Map:
- // ok
+ case reflect.Array, reflect.Slice:
+ sliceType = seqv.Type()
+ case reflect.Map:
+ sliceType = reflect.SliceOf(seqv.Type().Elem())
default:
return nil, errors.New("can't sort " + reflect.ValueOf(seq).Type().String())
}
// Create a list of pairs that will be used to do the sort
- p := pairList{SortAsc: true, SliceType: reflect.SliceOf(seqv.Type().Elem())}
+ p := pairList{SortAsc: true, SliceType: sliceType}
p.Pairs = make([]pair, seqv.Len())
var sortByField string