mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-25 22:00:58 +02:00
Merge commit '35dec7c96f7ee3eb17dd444f7067f0c776fb56ae'
This commit is contained in:
@@ -1,20 +1,15 @@
|
||||
---
|
||||
title: collections.Last
|
||||
linkTitle: last
|
||||
description: Slices an array to the last N elements.
|
||||
categories: [functions]
|
||||
description: Returns the given collection, limited to the last N elements.
|
||||
categories: []
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
function:
|
||||
action:
|
||||
aliases: [last]
|
||||
related:
|
||||
- functions/collections/After
|
||||
- functions/collections/First
|
||||
returnType: any
|
||||
signatures: [collections.Last INDEX COLLECTION]
|
||||
relatedFunctions:
|
||||
- collections.After
|
||||
- collections.First
|
||||
- collections.Last
|
||||
signatures: [collections.Last N COLLECTION]
|
||||
aliases: [/functions/last]
|
||||
---
|
||||
|
||||
@@ -23,3 +18,17 @@ aliases: [/functions/last]
|
||||
{{ .Render "summary" }}
|
||||
{{ end }}
|
||||
```
|
||||
|
||||
Set `N` to zero to return an empty collection.
|
||||
|
||||
```go-html-template
|
||||
{{ $emptyPageCollection := last 0 .Pages}}
|
||||
```
|
||||
|
||||
Use `last` and [`where`] together.
|
||||
|
||||
```go-html-template
|
||||
{{ range where .Pages "Section" "articles" | last 5 }}
|
||||
{{ .Render "summary" }}
|
||||
{{ end }}
|
||||
```
|
||||
|
Reference in New Issue
Block a user