Skip to main content

Template Syntax Reference

This page covers the template source syntax used by the visual response builder and by importTemplate(...). Most command authors should use Advanced Script examples from the other pages.

Template Source vs Advanced Script

Kicklet has two Engine v2 authoring modes:

  • Advanced Script is plain JavaScript. Write JavaScript at the top level and send chat output with async.messages.send(...), messages.send(...), or messages.reply(...).
  • Template Source is rendered text with {{...}} expressions. JavaScript is only valid inside a <script>...</script> block. The script block runs first and prepares values used by the text.

Do not mix the two formats. This is Advanced Script:

const roll = random.int(1, 100);
async.messages.send(`Rolled ${roll}.`);

This is Template Source:

Rolled {{roll}}.

<script>
const roll = random.int(1, 100);
</script>

This is not valid as one response source, because the JavaScript is outside a script block and the text expects template rendering:

Rolled {{roll}}.

const roll = random.int(1, 100);

Expressions

Use {{...}} to write one expression into the response.

Deaths: {{counters.get("deaths")}}

Script Block

A source file can prepare values in one script block at the bottom. The script runs first, then the response body is rendered.

Prepared value: {{roll}}.

<script>
const roll = random.int(1, 100);
</script>

Conditions

Conditions choose which text is rendered. Use them in visual-builder source or imported templates when a response needs branches.

{{if points.get(sender.username) >= 100}}
You can afford this.
{{else}}
You need more points.
{{end}}

Loops

Loops render repeated output from a list.

Active viewers:
{{for viewer in stats.randomActiveViewers(3)}}
{{viewer.username}}
{{end}}

Reusable Blocks

Reusable blocks define a named output block and render it later with data. They are local to the current source file.

{{define "entry"}}
#{{rank}} {{username}} - {{score}}
{{end}}

{{template "entry" {rank: 1, username: "Alice", score: 50}}}
{{template "entry" {rank: 2, username: "Bob", score: 35}}}

Imported Templates

Advanced Script can render remote template source with importTemplate(...). See Remote Imports for URL rules, data passing, hash pinning, caching, and runnable examples.

Engine v1

Engine v1 uses Go template syntax.

{{if ge 120 100}}
High score.
{{else}}
Keep going.
{{end}}
{{range $viewer := kicklet.ActiveViewersRandom 3}}
{{$viewer.Username}}
{{end}}