hugo/docs/content/en/functions/go-template/len.md
2023-10-20 09:43:56 +02:00

925 B

title description categories keywords menu function relatedFunctions aliases
len Returns the length of a string, slice, map, or collection.
functions
docs
parent
functions
aliases returnType signatures
int
len INPUT
len
strings.Count
strings.CountRunes
strings.CountWords
strings.RuneCount
/functions/len

{{% readfile file="/functions/_common/go-template-functions.md" %}}

With a string:

{{ "ab" | len }} → 2
{{ "" | len }} → 0

With a slice:

{{ slice "a" "b" | len }} → 2
{{ slice | len }} → 0

With a map:

{{ dict "a" 1 "b" 2  | len }} → 2
{{ dict | len }} → 0

With a collection:

{{ site.RegularPages | len }} → 42

You may also determine the number of pages in a collection with:

{{ site.RegularPages.Len }} → 42