Squiggly

Collections

Operating on lists and maps — head, tail, append, distinct, sort.

FunctionArityWhat
len1Length of a list / map / string
isEmpty1True iff the collection has zero items
nonEmpty1True iff the collection has at least one item
head1First element of a list
tail1All but the first
first1Alias for head
last1Last element
reverse1Reversed copy
sort1Sorted copy (natural ordering on the elements)
distinct1Drop duplicates, preserving original order
compact1Drop null and the empty-tuple () from a list
append2append elem list — append to the right
prepend2prepend elem list — prepend to the left

Examples

{{ .args | head }}                          first positional arg
{{ .args | tail | join ' ' }}               drop first, rejoin

{{ for n <- .nums | distinct | sort }}      unique then sorted
  {{ n }}
{{ end }}

{{ if .items | nonEmpty }}{{ end }}        guard against empty list

{{ .tags | append 'featured' | join ' ' }}  add a tag, render

Maps

for k, v <- m iterates a map. Many of the list builtins above work on maps too — len m returns the entry count, isEmpty m checks for an empty map.

To pluck a value by key, use […] indexing in expressions:

{{ .config['baseURL'] }}
{{ .frontmatter.tags }}        // dot syntax works for string keys