Skip to content

Syntax

Text is printed as it is. An action is anything inside {{ and }}.

Hello {{ .User.Username }}!
{{/* This is a comment, it is not printed */}}

{{- takes away the spaces, tabs and new lines before the action, and -}} the ones after it.

a {{- "b" -}} c

prints abc. Without the dashes, the spaces would be printed.

Kind Examples Notes
Text "hello", "line\nbreak", `raw text` In "..." you can write \n, \t, \r, \" and \\. Text in backticks is not changed
Number 5, -3, 2.5
Boolean true, false
Nil nil No value
List cslice 1 2 3 See Functions
Map sdict "a" 1 "b" 2 Names and values

IDs are text. A Discord ID has 18 digits and a number that big loses its last digits, so write IDs between quotes: "123456789012345678". Writing one as a number is a mistake that is reported when the code is checked.

In a condition, these are false: false, nil, 0, an empty text "", an empty list and an empty map. Everything else is true.

Value Printed as
Text The text
Number 5, 2.5
Boolean true, false
Nil Nothing
List [1 2 3]
Map map[a:1 b:2]

The data the code can read is written with a dot: .User.Username. . alone is the current value, and $ is always the whole data, even inside a loop. See Data.

Reading a name that does not exist gives nil. Reading inside nil (.Nope.Deep when .Nope is nil) is a mistake.

{{ $count := 0 }} {{/* create */}}
{{ $count = add $count 1 }} {{/* change */}}
{{ $count }}
  • := creates a variable in the current block. = changes one that already exists, from any block inside it.
  • A variable created inside if, range or with only exists until its end.
  • Using a variable that was not created is a mistake.

A function is written first and its arguments follow, separated by spaces. Parentheses call a function inside another.

{{ add 1 2 }} {{/* 3 */}}
{{ sub 10 (mult 2 3) }} {{/* 4 */}}
{{ printf "%s has %d" "Liam" 5 }}

A function cannot be used as a value without calling it.

| gives the result on its left to the function on its right as its last argument, like in Go templates.

{{ " hello " | trim | upper }} {{/* HELLO */}}
{{ 3 | add 4 | mult 2 }} {{/* mult 2 (add 4 3) = 14 */}}

Because the value goes last, be careful with functions that take the main value first, such as split and join: {{ join (split "a-b" "-") "+" }} is clearer than a pipe.

{{ if eq .User.Username "Liam" }}
Hi Liam!
{{ else if gt (len .Args) 2 }}
Many arguments.
{{ else }}
Hello.
{{ end }}

else if and else are optional. The condition is any value, with the rules of true and false above.

with runs its block only if the value is true, and inside it . is that value:

{{ with .Member }}{{ .Nick }}{{ else }}No member{{ end }}
{{ range $index, $value := .Args }}{{ $index }}: {{ $value }}
{{ end }}
Form What it does
range $i, $v := list Index and value
range $v := list Only the value
range list Only the value, as .
range $k, $v := map Key and value, in alphabetical order of the keys
  • {{ break }} leaves the loop and {{ continue }} goes to the next turn. They only work inside a range.
  • {{ else }} in a range runs when the list is empty.
  • {{ return }} stops the code at once. What was printed before stays.
  • To repeat something a number of times: {{ range seq 0 5 }}...{{ end }}.

and and or always look at all their arguments before deciding, they do not stop at the first one.