> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.repliers.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# Email Template Syntax Guide

## Overview

This documentation covers the custom templating syntax used in our email messaging service. The syntax uses double curly braces `{{}}` to define dynamic content areas, conditional logic, and loops.

**CRITICAL**: When providing email templates to our service, all templating syntax must be preserved exactly as shown below. Removing or modifying these template tags will break the dynamic functionality.

## Core Syntax Elements

### 1. Variable Interpolation

Variables are inserted using double curly braces:

```
{{variable_name}}
```

**Examples:**

```
{{business_name}}
{{business_address}}
{{price}}
{{neighbourhood}}
{{mlsnumber}}
```

### 2. Conditional Statements

Conditional logic uses `{{if}}` and `{{end}}` blocks:

```
{{if condition}}
  Content to show when condition is true
{{end}}
```

**Simple conditions:**

```
{{if editSearch}}
  <a href="{{{adjust_search_url}}}">Edit Your Search</a>
{{end}}

{{if logo}}
  <img src="{{{logo}}}" alt="Company Logo">
{{end}}

{{if agentAvatar}}
  <img src="{{{agentAvatar}}}" height="50"/>
{{end}}
```

**Advanced conditions with comparisons:**

```
{{if #listings > 1}}
  Here are some listings that match
{{else}}
  Here's a listing that matches
{{end}}
```

### 3. Loop Iterations

Loops use `{{each}}` and `{{end}}` blocks:

```
{{each collection_name}}
  Content that repeats for each item
{{end}}
```

**Examples:**

```
{{each listings}}
  <div class="listing">
    <h3>${{loop_var.price}}</h3>
    <p>{{loop_var.neighbourhood}} - {{loop_var.mlsnumber}}</p>
  </div>
{{end}}
```

### 4. Loop Variables

Within loops, access individual item properties using `loop_var`:

```
{{each listings}}
  {{loop_var.property_name}}
{{end}}
```

**Common loop variables:**

* `{{loop_var.price}}`
* `{{loop_var.neighbourhood}}`
* `{{loop_var.mlsnumber}}`
* `{{loop_var.address}}`
* `{{loop_var.bedrooms}}`
* `{{loop_var.bathrooms}}`
* `{{loop_var.sqft}}`
* `{{loop_var.image}}`
* `{{loop_var.url}}`

### 5. Special Syntax for URLs

For URLs and HTML content, use triple braces to avoid escaping:

```
{{{variable_name}}}
```

**Examples:**

```
<a href="{{{loop_var.url}}}">View Property</a>
<a href="{{{adjust_search_url}}}">Adjust Search</a>
<a href="{{{unsubscribe_url}}}">Unsubscribe</a>
<img src="{{{agentAvatar}}}"/>
```

### 6. Array Length and Comparisons

Access array length using `#` prefix:

```
{{if #listings > 1}}
  Multiple listings content
{{else}}
  Single listing content
{{end}}
```

## Template Structure Example

Based on the new-listing-alert template, here's a typical structure:

```
<!DOCTYPE html>
<html>
<head>
    <title>{{email_subject}}</title>
</head>
<body>
    {{if logo}}
        <div class="header">
            <img src="{{logo}}" alt="{{business_name}}">
            <h1>{{business_name}}</h1>
            <p>{{business_address}}</p>
        </div>
    {{end if}}
    
    <div class="content">
        <h2>New Listings Alert</h2>
        
        {{each listings}}
            <div class="listing-item">
                <div class="price">${{loop_var.price}}</div>
                <div class="details">
                    {{loop_var.neighbourhood}} - MLS# {{loop_var.mlsnumber}}
                </div>
                {{if loop_var.image}}
                    <img src="{{loop_var.image}}" alt="Property Image">
                {{end if}}
            </div>
        {{end each}}
        
        {{if editSearch}}
            <div class="footer">
                <a href="{{edit_search_url}}">Edit Your Search Preferences</a>
            </div>
        {{end if}}
    </div>
    
    
</body>
</html>
```

## Available Variables

Our system provides the following data that can be used in your templates:

### Business Information

* `{{business_name}}` - Your company name
* `{{business_address}}` - Your business address
* `{{logo}}` - URL to your company logo (use `{{{logo}}}` for URLs)

### Agent Information

* `{{fromName}}` - Agent or sender name
* `{{agentAvatar}}` - Agent profile image URL (use `{{{agentAvatar}}}`)
* `{{agentEmail}}` - Agent email address
* `{{agentPhone}}` - Agent phone number

### Message Information

* `{{datetime}}` - Date and time of the message
* `{{to.firstname}}` - Recipient's first name
* `{{search}}` - Search criteria description
* `{{search_name}}` - The name given to the saved search

### Navigation/Action URLs (use triple braces)

* `{{{search_url}}}` - Link to search results (use `{{{search_url}}}`)
* `{{{adjust_search_url}}}` - Link to modify search criteria
* `{{{unsubscribe_url}}}` - Unsubscribe link
* `{{{settings_url}}}` - Profile and settings link

### Feature Flags

* `{{editSearch}}` - Boolean indicating if edit search functionality is available
* `{{showPoweredBy}}` - Boolean to show/hide "Powered by" footer

### Account Information

* `{{account.username}}` - Account username (for tracking/analytics)

### Listing Data (available in loops)

When using `{{each listings}}`, each listing contains:

* `{{loop_var.price}}` - Property price
* `{{loop_var.neighbourhood}}` - Area/neighborhood name
* `{{loop_var.mlsnumber}}` - MLS listing number
* `{{loop_var.address}}` - Property address
* `{{loop_var.bedrooms}}` - Number of bedrooms
* `{{loop_var.bathrooms}}` - Number of bathrooms
* `{{loop_var.sqft}}` - Square footage
* `{{loop_var.image}}` - Property image URL
* `{{{loop_var.url}}}` - Link to property details (use triple braces)

### Special Variables

* `{{#listings}}` - Count of listings in the array

## Common Patterns

### 1. Optional Content Sections

```
{{if user_preferences}}
    <div class="preferences">
        <h3>Your Search Preferences</h3>
        <p>Price Range: ${{user_preferences.min_price}} - ${{user_preferences.max_price}}</p>
        <p>Areas: {{user_preferences.areas}}</p>
    </div>
{{end if}}
```

### 2. Dynamic Lists with Fallbacks

```
{{if listings}}
    {{each listings}}
        <div class="listing">{{loop_var.address}}</div>
    {{end}}
{{end}}

{{if !listings}}
    <p>No new listings match your criteria.</p>
{{end}}
```

### 3. Conditional Content Based on Count

```
{{if #listings > 1}}
    <h2>Here are {{#listings}} listings that match your search</h2>
{{else}}
    <h2>Here's a listing that matches your search</h2>
{{end}}
```

### 4. Nested Conditions

```
{{if user_type}}
    {{if user_type == "premium"}}
        <div class="premium-content">Premium features here</div>
    {{end}}
    {{if user_type == "basic"}}
        <div class="basic-content">Basic features here</div>
    {{end}}
{{end}}
```

## Troubleshooting Common Issues

### ❌ Incorrect Syntax Examples

**Missing end tags:**

```
{{if condition}}
    Content here
<!-- Missing {{end}} -->
```

**Incorrect variable names in loops:**

```
{{each listings}}
    {{listings.price}}  <!-- Wrong - should be {{loop_var.price}} -->
{{end}}
```

**Wrong URL syntax:**

```
<a href="{{loop_var.url}}">  <!-- Should be {{{loop_var.url}}} -->
```

**Malformed conditions:**

```
{{if condition}  <!-- Missing closing brace -->
```

### ✅ Correct Syntax Examples

**Proper conditional blocks:**

```
{{if condition}}
    Content here
{{end}}
```

**Correct loop variable usage:**

```
{{each listings}}
    {{loop_var.price}}
{{end}}
```

**Proper URL handling:**

```
<a href="{{{loop_var.url}}}">View Property</a>
<img src="{{{agentAvatar}}}"/>
```

**Array count conditions:**

```
{{if #listings > 1}}
    Multiple listings
{{else}}
    Single listing
{{end}}
```

## Best Practices

1. **Always close blocks**: Every `{{if}}` needs `{{end}}`, every `{{each}}` needs `{{end}}`
2. **Use triple braces for URLs**: All URLs and HTML content should use `{{{variable}}}` syntax
3. **Template Testing**: We will test your template with sample data to ensure it renders correctly
4. **Validate HTML structure**: Ensure your HTML is valid and well-formed
5. **Use consistent naming**: Stick to a consistent naming convention for variables (e.g., snake_case or camelCase)

## Troubleshooting

If you encounter issues with template syntax:

1. Verify all opening tags have corresponding closing tags
2. Check variable names match your data structure exactly
3. Ensure loop variables use `loop_var.` prefix
4. Validate your JSON data structure matches template expectations

# What questions does this article answer?

* What templating language and syntax does Repliers use for email templates?  
* How do I insert dynamic variables into my email templates?  
* How do I write conditional logic (`if`, `else`, `end`) in templates?  
* How do I loop over collections of listings or items in an email?  
* When do I need to use double braces `{{ }}` vs triple braces `{{{ }}}`?  
* What template variables are available for business, agent, account, and listing data?  
* How can I correctly handle counts (like `#listings`) and comparisons in templates?  
* What are common templating mistakes and how can I troubleshoot them? 