🧠 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
listsis a Map, use.__keyand.__value. - If
listsis a List, use.__indexand..
📌 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__valueinto 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