Array / Slices
These are the number of ways to manipulate array / slices in Hugo.
Covert String to Slice
Covert String to Slice
To convert strings to slice, you use split
command:
{{- split "String" "delimiter" -}}
Example:
{{- $keywords := split "Hello World" " " -}}
# You get:
[ "Hello", "World"]
Convert Slice to String
Convert Slice to String
To convert slice to strings, you use delimit
command:
{{- delimit $slice $join_pattern $optional_last_element_join_pattern -}}
Example:
{{- delimit ["Hello", "World", "Smith"] ", " ", and" -}}
# You get:
"Hello, World, and Smith"
{{- delimit ["Hello", "World", "Smith"] ", " -}}
# You get:
"Hello, World, Smith"