Skip to content

🧠 Template Variables and Control Flow Examples


🔡 Input Data Example

{
  "myMap": { "name": "John", "age": 30 },
  "myList": ["apple", "banana"],
  "isAdmin": true
}

🔁 {{#range lists}} ... {{%}}

Loops through a list or map.

  • If lists is a Map, use .__key and .__value.
  • If lists is a List, use .__index and ..

📌 Example (Map):

{{#range myMap}}
  {{.__key}}: {{.__value}}
{{%}}

📤 Output:

  name: John
  age: 30

📌 Example (List):

{{#range myList}}
  {{.__index}}: {{.}}
{{%}}

📤 Output:

  0: apple
  1: banana

{{#if ...}} ... {{%}} and {{^ ...}} ... {{%}}

Control flow for booleans or value presence.

  • {{#if condition}} renders if true
  • {{^ condition}} renders if false

📌 Example:

{{#if isAdmin}}
  Admin Access
{{%}}

{{^ isAdmin }}
  Guest Access
{{%}}

📤 Output:

  Admin Access

🔗 Function Chaining

Call methods directly on values using dot chaining.

📌 Example:

{{ "my_string".toCamelCase().toPascalCase() }}

📤 Output:

  MyString

📦 Variables

You can store and retrieve values inside the template:

  • {{ 'var'.setVar(__value) }} — stores __value into a variable
  • {{ getVar('var') }} — retrieves stored variable

📌 Example:

{{ 'userId'.setVar("abc123") }}
User ID: {{ getVar('userId') }}

📤 Output:

  User ID: abc123

💬 Inline Comments

Use {{! comment }} for inline comments. These are ignored.

📌 Example:

{{! This is a comment }}
Hello

📤 Output:

  Hello