mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-22 21:42:50 +02:00
Merge commit 'e509cac533600cf4fa8382c9cdab78ddd82db688'
This commit is contained in:
55
docs/content/en/functions/go-template/len.md
Normal file
55
docs/content/en/functions/go-template/len.md
Normal file
@@ -0,0 +1,55 @@
|
||||
---
|
||||
title: len
|
||||
description: Returns the length of a string, slice, map, or collection.
|
||||
categories: [functions]
|
||||
keywords: []
|
||||
menu:
|
||||
docs:
|
||||
parent: functions
|
||||
function:
|
||||
aliases: []
|
||||
returnType: int
|
||||
signatures: [len INPUT]
|
||||
relatedFunctions:
|
||||
- len
|
||||
- strings.Count
|
||||
- strings.CountRunes
|
||||
- strings.CountWords
|
||||
- strings.RuneCount
|
||||
aliases: [/functions/len]
|
||||
---
|
||||
|
||||
{{% readfile file="/functions/_common/go-template-functions.md" %}}
|
||||
|
||||
With a string:
|
||||
|
||||
```go-html-template
|
||||
{{ "ab" | len }} → 2
|
||||
{{ "" | len }} → 0
|
||||
```
|
||||
|
||||
With a slice:
|
||||
|
||||
```go-html-template
|
||||
{{ slice "a" "b" | len }} → 2
|
||||
{{ slice | len }} → 0
|
||||
```
|
||||
|
||||
With a map:
|
||||
|
||||
```go-html-template
|
||||
{{ dict "a" 1 "b" 2 | len }} → 2
|
||||
{{ dict | len }} → 0
|
||||
```
|
||||
|
||||
With a collection:
|
||||
|
||||
```go-html-template
|
||||
{{ site.RegularPages | len }} → 42
|
||||
```
|
||||
|
||||
You may also determine the number of pages in a collection with:
|
||||
|
||||
```go-html-template
|
||||
{{ site.RegularPages.Len }} → 42
|
||||
```
|
Reference in New Issue
Block a user