> ## Documentation Index
> Fetch the complete documentation index at: https://fyre.bot/llms.txt
> Use this file to discover all available pages before exploring further.

# Template Syntax

> Learn about Fyre's message template syntax and how it can be used to level-up your customisation.

<Info>
  Fyre's templating is based on [Handlebars](https://handlebarsjs.com/guide/#what-is-handlebars).
  Visit their website to learn more advanced logic and syntax.
</Info>

## Basic Syntax

Handlebars has a simple to use syntax for inserting variables into text.
Templating is built with [Fyre's Variables](./variables) in mind to give you the best experience.

You can use all
[Discord Markdown](https://support.discord.com/hc/en-us/articles/210298617-Markdown-Text-101-Chat-Formatting-Bold-Italic-Underline)
in your templates, Handlebars just adds additional syntax for variables.

To insert a variable, surround it in triple braces/curly brackets.
We use triple braces because they don't do [HTML Escaping](https://handlebarsjs.com/guide/#html-escaping).

If your variable won't return any special characters (`& \ " ' = <>`) you can use double braces instead of triple braces.

<CodeGroup>
  ```handlebars Template theme={null}
  Welcome {{{user.mention}}} to {{{guild.name}}}!
  ```

  ```txt Result theme={null}
  Welcome @Fallen to Fyre Support!
  ```
</CodeGroup>

## Basic Logic

Handlebars offers a few helpers to work with optional variables or do simple logic checks.

### If / If Else

To check if an optional variable exists, or if a boolean variable is true, use `#if`.
You don't need to have an `{{else}}` statement if you don't need one, but it's provided in this example anyway.

<CodeGroup>
  ```handlebars Template theme={null}
  {{#if track.nowPlaying}}
  Track is Now Playing
  {{else}}
  Track isn't Playing
  {{/if}}

  Track Name: {{{track.name}}}
  ```

  ```txt Result (Playing) theme={null}
  Track is Now Playing

  Track Name: The Outfield
  ```

  ```txt Result (Stopped) theme={null}
  Track isn't Playing

  Track Name: The Outfield
  ```
</CodeGroup>

### Unless

Unless is the opposite of if. Use it to check if a variable doesn't exist, or if a boolean value is false, use `#unless`.

<CodeGroup>
  ```handlebars Template theme={null}
  {{#unless track.loved}}
  Track isn't Loved!\n
  {{/unless}}
  Track Name: The Outfield
  ```

  ```txt Result (Loved) theme={null}
  Track Name: The Outfield
  ```

  ```txt Result (No Love) theme={null}
  Track isn't Loved!

  Track Name: The Outfield
  ```
</CodeGroup>

## Custom Helpers

Fyre has some custom helpers to add additional functionality to Handlebars.

### Random

You can use the `random` helper to randomly select one of the provided strings or numbers.
This helper should technically support infinite arguments, but it's only been tested up to 10.

<CodeGroup>
  ```handlebars Template theme={null}
  {{random "Example" "Of" "Random" "Strings"}}
  ```

  ```txt Result 1 theme={null}
  Random
  ```

  ```txt Result 2 theme={null}
  Example
  ```
</CodeGroup>

### Format Number

You can use the `formatNumber` helper to format long numbers with commas or periods.

This helper supports using an
[IETF Language Tag](https://en.wikipedia.org/wiki/IETF_language_tag)
for regional formatting (eg. "en-US" or "en-DK").

<CodeGroup>
  ```handlebars Template theme={null}
  Track Name: {{{track.name}}}
  Total Plays: {{formatNumber track.totalPlayCount}}
  Total Plays (en-DK): {{formatNumber track.totalPlayCount "en-DK"}}
  ```

  ```txt Result theme={null}
  Track Name: The Outfield
  Total Plays: 28,200
  Total Plays (en-DK): 28.200
  ```
</CodeGroup>

### Format Date & Time

You can use the `formatDate` helper to format a timestamp into any date format.

This helper works with both [Dayjs](https://day.js.org/docs/en/parse/string-format)
and [Dayjs Advanced](https://day.js.org/docs/en/plugin/advanced-format) formatting options.

<CodeGroup>
  ```handlebars Template theme={null}
  {{formatDate 946713600 "DD/MM/YYYY HH:mm"}}
  ```

  ```txt Result theme={null}
  01/01/2000 00:00
  ```
</CodeGroup>

### Format List

You can use the `formatList` helper to join an array of items into a string.

<CodeGroup>
  ```handlebars Template theme={null}
  {{formatList afk.mentionLinks ", "}}
  ```

  ```txt Result theme={null}
  https://discord.com/channels/1370922624397606952/1374080670304833547/1496128374199025674, https://discord.com/channels/1370922624397606952/1374080670304833547/1480784410482708731, https://discord.com/channels/1370922624397606952/1374080670304833547/1466002583016706193
  ```
</CodeGroup>

### Capital Case

Capitalize the first letter of every word in a sentence.

<CodeGroup>
  ```handlebars Template theme={null}
  {{capitalCase "Hello, this is a test!"}}
  ```

  ```txt Result theme={null}
  Hello, This Is A Test!
  ```
</CodeGroup>
