length
Returns the number of UTF-8 bytes in a string, so a multi-byte character such as 'é' counts as more than one.
InputArgumentsReturns
Sourcestringno argumentsint[]byteno argumentsintanyno argumentsintBasicSource
Returns the number of UTF-8 bytes in a string, so a multi-byte character counts as more than one.
Given
{"name": "Ada"}Template
{{ name | length }}Result
3UnicodeSource
Counts UTF-8 bytes rather than runes, so the accented "é" adds two to the total.
Given
{"name": "café"}Template
{{ name | length }}Result
5BasicSource
Returns the number of bytes in a byte-slice value.
Given
{"raw": []byte("hello")}Template
{{ raw | length }}Result
5BasicSource
Counts the elements of a slice, array, or map, the fallback clause reached for a non-string value.
Given
{"items": ["a", "b", "c", "d"]}Template
{{ items | length }}Result
4MapSource
Counts the entries of a map.
Given
{"headers": {"a": 1, "b": 2}}Template
{{ headers | length }}Result
2