Template Syntax Reference¶
This is a complete reference guide for Templify's template syntax. Use this as a quick lookup when creating templates.
Table of Contents¶
- Placeholders
- Conditionals
- Loops
- Operators
- Format Specifiers
- Loop Variables
- Markdown Formatting
- Line Breaks in Data
Placeholders¶
Placeholders are replaced with data from your JSON file. They're wrapped in double curly braces: {{...}}
Simple Placeholder¶
JSON:
Template:
Output:
Nested Properties (Dot Notation)¶
Access nested data using dots (.):
JSON:
Template:
Array Indexing¶
Access specific array items by index (starting at 0):
JSON:
{
"Colors": ["Red", "Green", "Blue"],
"Users": [
{ "Name": "Alice", "Age": 25 },
{ "Name": "Bob", "Age": 30 }
]
}
Template:
Case Sensitivity¶
JSON keys are case-sensitive. {{Name}} and {{name}} are different. Always match the exact case used in your JSON data.
Conditionals¶
Conditionals let you show or hide content based on data values.
Basic Conditional¶
JSON:
Template:
Conditional with Else¶
JSON:
Template:
Conditional with ElseIf¶
Use {{#elseif}} for multiple conditions:
{{#if Condition1}}
Content for condition 1
{{#elseif Condition2}}
Content for condition 2
{{#elseif Condition3}}
Content for condition 3
{{#else}}
Default content
{{/if}}
JSON:
Template:
{{#if Score >= 90}}
Grade: A
{{#elseif Score >= 80}}
Grade: B
{{#elseif Score >= 70}}
Grade: C
{{#else}}
Grade: F
{{/if}}
Output:
Note: The {{#else}} branch must always be last.
Conditional with Comparisons¶
Template:
{{#if Age >= 18}}
You are an adult.
{{/if}}
{{#if Score > 90}}
Excellent!
{{#else}}
Keep trying!
{{/if}}
Multiple Conditions¶
Use and or or to combine conditions:
{{#if Condition1 and Condition2}}
Both are true
{{/if}}
{{#if Condition1 or Condition2}}
At least one is true
{{/if}}
JSON:
Template:
{{#if Age >= 18 and HasLicense}}
You can rent a car.
{{/if}}
{{#if Country = "USA" or Country = "Canada"}}
North American customer
{{/if}}
Negation¶
Use not to negate a condition:
{{#if not IsExpired}}
Subscription is active
{{/if}}
{{#if not (Age < 18)}}
You are an adult
{{/if}}
Loops¶
Loops repeat content for each item in an array.
Basic Loop¶
JSON:
Template:
Output:
Nested Loops¶
You can nest loops within each other:
JSON:
{
"Departments": [
{
"Name": "Sales",
"Employees": [
{ "Name": "Alice" },
{ "Name": "Bob" }
]
},
{
"Name": "Engineering",
"Employees": [
{ "Name": "Charlie" },
{ "Name": "Diana" }
]
}
]
}
Template:
{{#foreach Departments}}
Department: {{Name}}
{{#foreach Employees}}
- {{Name}}
{{/foreach}}
{{/foreach}}
Loops in Tables¶
Loops can repeat table rows:
Template (in Word table):
| Product | Price |
|---|---|
| {{#foreach Items}}{{Name}} | ${{Price}}{{/foreach}} |
The row will be repeated for each item.
Operators¶
Comparison Operators¶
| Operator | Meaning | Example |
|---|---|---|
= |
Equal to | {{#if Status = "Active"}} |
!= |
Not equal to | {{#if Status != "Pending"}} |
> |
Greater than | {{#if Age > 18}} |
< |
Less than | {{#if Price < 100}} |
>= |
Greater than or equal | {{#if Score >= 90}} |
<= |
Less than or equal | {{#if Stock <= 10}} |
Logical Operators¶
| Operator | Meaning | Example |
|---|---|---|
and |
Both conditions true | {{#if Age >= 18 and HasLicense}} |
or |
At least one true | {{#if IsVIP or IsPremium}} |
not |
Negates condition | {{#if not IsExpired}} |
Operator Precedence¶
- Parentheses
() not- Comparison operators (
=,!=,>, etc.) andor
Example:
Format Specifiers¶
Format specifiers control how values are displayed. Add them after a colon (:) in the placeholder.
Basic Syntax¶
Common Formats¶
| Format | Description | Example Input | Example Output |
|---|---|---|---|
:uppercase |
Convert to UPPERCASE | "hello" | HELLO |
:lowercase |
Convert to lowercase | "HELLO" | hello |
:yesno |
true/false → Yes/No | true | Yes |
:checkbox |
true/false → ☑/☐ | false | ☐ |
:number:N2 |
Format number with 2 decimals | 1234.5 | 1,234.50 |
:currency |
Format as currency | 1234.5 | $1,234.50 |
:date:yyyy-MM-dd |
Format date | (date value) | 2024-01-15 |
Examples¶
JSON:
{
"CustomerName": "alice johnson",
"IsActive": true,
"HasDiscount": false,
"Price": 1234.567,
"OrderDate": "2024-01-15"
}
Template:
Name: {{CustomerName:uppercase}}
Status: {{IsActive:yesno}}
Discount: {{HasDiscount:checkbox}}
Price: {{Price:currency}}
Date: {{OrderDate:date:MMMM d, yyyy}}
Output:
For more format specifier details, see Format Specifiers Guide.
Loop Variables¶
Special variables available inside loops:
{{@index}}¶
The current loop iteration index (starts at 0):
Template:
Output:
{{@first}}¶
True if this is the first iteration:
Template:
{{@last}}¶
True if this is the last iteration:
Template:
Output:
{{@count}}¶
Total number of items in the loop:
Template:
Output:
Markdown Formatting¶
Apply formatting to text using markdown syntax in your JSON data:
Bold¶
Or use underscores:
Italic¶
Or use underscores:
Strikethrough¶
Bold + Italic¶
Combining with Template Formatting¶
The markdown formatting is merged with the template's formatting. If your template has red text, and you add **bold** in the data, the output will be red bold text.
Line Breaks in Data¶
Newline characters in your JSON data are automatically converted to line breaks in Word:
Supported formats:
- \n - Unix/Linux/macOS
- \r\n - Windows
- \r - Legacy Mac
Combining with Markdown¶
Line breaks work together with markdown formatting:
Output will have three lines, each with bold text for "Step X:".
Special Characters¶
Literal Curly Braces¶
To include literal {{ or }} in your document without creating a placeholder, there's currently no escape mechanism. Best practice: avoid using {{ in your document text unless it's a placeholder.
Whitespace¶
Templify preserves whitespace in your templates:
Will output with the indentation preserved.
Quick Syntax Summary¶
| Feature | Syntax | Example |
|---|---|---|
| Placeholder | {{Name}} |
{{CustomerName}} |
| Nested | {{Parent.Child}} |
{{Customer.Address.City}} |
| Array | {{Array[0]}} |
{{Colors[0]}} |
| If | {{#if ...}}...{{/if}} |
{{#if IsActive}}...{{/if}} |
| If/Else | {{#if ...}}...{{#else}}...{{/if}} |
See above |
| If/ElseIf | {{#if ...}}...{{#elseif ...}}...{{/if}} |
See above |
| Loop | {{#foreach ...}}...{{/foreach}} |
{{#foreach Items}}...{{/foreach}} |
| Format | {{Name:format}} |
{{Price:currency}} |
| Loop Index | {{@index}} |
{{@index}} |
| Loop First | {{@first}} |
{{#if @first}}...{{/if}} |
| Loop Last | {{@last}} |
{{#if @last}}...{{/if}} |
| Loop Count | {{@count}} |
{{@count}} |
Common Patterns¶
Numbered List¶
Comma-Separated List¶
Conditional with Multiple Checks¶
Nested Conditionals¶
{{#if IsLoggedIn}}
{{#if IsPremium}}
Premium content
{{#else}}
Regular content
{{/if}}
{{#else}}
Please log in
{{/if}}
Table with Conditional Rows¶
| Product | Price | Status |
|---------|-------|--------|
{{#foreach Products}}
| {{Name}} | {{Price}} | {{#if InStock}}Available{{#else}}Out of Stock{{/if}} |
{{/foreach}}
Best Practices¶
- Match case exactly -
{{Name}}must match"Name"in JSON - Test with simple data first - Start with basic JSON and gradually add complexity
- Use meaningful names -
{{CustomerFirstName}}is better than{{N1}} - Validate JSON - Use jsonlint.com to check JSON syntax
- Comment your templates - Add notes in Word comments about complex logic
- Keep conditionals simple - Break complex logic into multiple simpler conditionals
Next Steps¶
- Placeholders Guide - Deep dive into placeholder usage
- Conditionals Guide - Detailed conditional examples
- Loops Guide - Advanced loop techniques
- Format Specifiers - Complete formatting reference
- Examples Gallery - Real-world template examples
Quick Troubleshooting¶
| Problem | Solution |
|---|---|
| Placeholder not replaced | Check that JSON key matches exactly (case-sensitive) |
| Conditional not working | Verify operator syntax and value types |
| Loop not repeating | Ensure JSON has an array for the loop variable |
| Formatting not applied | Check format specifier syntax: {{Value:format}} |
| Syntax error | Validate JSON at jsonlint.com |
| Missing data | Check for typos in placeholder names |
For more help, see Best Practices or FAQ.