Skip to main content

Text Templating Engine

The Bookla email templating engine uses a powerful template syntax to create dynamic, personalized email content. This system allows you to insert booking data, use conditional logic, and create sophisticated email templates that adapt to different scenarios.

Basic Variable Substitution

The simplest form of templating involves replacing variables with actual booking data using double curly braces:

Dear {{.clientFirstName}} {{.clientLastName}},

Your booking for {{.service}} with {{.resource}} is confirmed for {{.startDate}} at {{.startTime}}.

Booking reference: {{.bookingId}}

Interactive Template Preview

Interactive Template Preview

Edit the template below to see how variables are replaced with actual data. You can also customize the sample data to test with your own values.

Template Input

Generated Output

Sample Data

{ "clientFirstName": "John", "clientLastName": "Doe", "clientEmail": "john@example.com", "company": "Beauty Salon", "companyId": "abc-def-123", "service": "Haircut", "serviceId": "haircut-premium", "resource": "Bob the Barber", "resourceId": "barber-bob", "startDate": "2025-02-18", "startTime": "10:00", "endDate": "2025-02-18", "endTime": "11:00", "bookingId": "123456", "metaData": { "videoUrl": "https://example.com/prep-video.mp4", "notes": "Please use fragrance-free products" } }

Available Variables

The templating engine provides access to comprehensive booking data:

Client Information

  • {{.clientFirstName}} - Customer's first name
  • {{.clientLastName}} - Customer's last name
  • {{.clientEmail}} - Customer's email address

Booking Details

  • {{.service}} - Service name
  • {{.serviceId}} - Service identifier
  • {{.resource}} - Staff member or resource name
  • {{.startDate}} - Appointment date (YYYY-MM-DD)
  • {{.startTime}} - Appointment start time (HH:MM)
  • {{.endTime}} - Appointment end time (HH:MM)
  • {{.bookingId}} - Unique booking identifier
  • {{.companyId}} - Company identifier

Tickets

  • {{.tickets}} - Tickets information (if applicable). Object containing ticket details where key is ticket name and value is ticket count.

Custom Metadata

  • {{.metaData}} - Access to custom booking metadata
  • {{index .metaData "key"}} - Access specific metadata field

Conditional Logic

The templating engine supports conditional statements to create dynamic content based on booking data:

Basic Conditionals

{{if eq .serviceId "haircut-1"}}
You've booked our premium haircut service!
{{else}}
Thank you for your standard booking.
{{end}}

Multiple Conditions

{{if eq .resource "Bob the Barber"}}
Bob is looking forward to seeing you!
{{else if eq .resource "Alice the Stylist"}}
Alice will provide you with our signature styling experience.
{{else}}
Our professional team is ready to serve you.
{{end}}

Logical Operators

Use and, or, and not to combine conditions:

{{if and (eq .resource "Bob the Barber") (eq .startTime "10:00")}}
Bob is ready for your morning appointment!
{{else}}
We look forward to seeing you.
{{end}}

Comparison Operators

The engine supports various comparison operators for numeric and string values:

Equality and Inequality

  • eq - Equal to
  • ne - Not equal to

Numeric Comparisons

  • gt - Greater than
  • ge - Greater than or equal to
  • lt - Less than
  • le - Less than or equal to

Example with Variables

{{$duration := 60}}
Your appointment will last {{$duration}} minutes.
{{if gt $duration 30}}
Please plan accordingly for this longer appointment.
{{else}}
This is a quick service.
{{end}}

Example with tickets

Display list of tickets if they exist:

{{if .tickets}}
Tickets:
{{- range $key, $value := .tickets}}
{{$key}}: {{$value}}
{{- end}}
{{end}}

Working with Metadata

Access custom metadata fields using the index function:

Simple Metadata Access

{{if index .metaData "videoUrl"}}
Watch our welcome video: {{index .metaData "videoUrl"}}
{{end}}

Nested Metadata

{{if index (index .metaData "google_calendar") "video_url"}}
Join video call: {{index (index .metaData "google_calendar") "video_url"}}
{{end}}

Safe Metadata Access

{{if and .metaData (index .metaData "google_calendar")}}
{{if index (index .metaData "google_calendar") "video_url"}}
Join video call: {{index (index .metaData "google_calendar") "video_url"}}
{{end}}
{{end}}

Advanced Features

Iterating Over Data

Booking details:
{{range $key, $value := .metaData}}
{{$key}}: {{$value}}
{{end}}

Variables and Functions

{{$greeting := "Hello"}}
{{$greeting}} {{.clientFirstName}},

{{if eq .startTime "10:00"}}
{{$greeting}} again! Early bird special applies.
{{end}}

Best Practices

Template Structure

  1. Start Simple: Begin with basic variable substitution
  2. Add Logic Gradually: Introduce conditionals as needed
  3. Test Thoroughly: Use the preview feature to verify output
  4. Handle Edge Cases: Use safe metadata access patterns

Performance Considerations

  • Avoid deeply nested conditionals
  • Use variables for repeated values
  • Keep template logic simple and readable

Error Handling

  • Always check if metadata exists before accessing
  • Use fallback values for optional fields
  • Test templates with various data scenarios

Example Templates

Conditional Service Messages

Hello {{.clientFirstName}},

{{if eq .serviceId "haircut-premium"}}
You've selected our premium haircut service. Our senior stylist will provide you with a personalized consultation and cut.
{{else if eq .serviceId "haircut-standard"}}
Thank you for choosing our standard haircut service. You'll receive a professional cut from our experienced team.
{{else}}
Thank you for your booking. We look forward to providing you with excellent service.
{{end}}

{{if and (eq .startTime "10:00") (eq .resource "Bob the Barber")}}
Special note: Bob is known for his exceptional morning appointments. Please arrive 10 minutes early.
{{end}}

Best regards,
The Team

Metadata-Rich Template

Dear {{.clientFirstName}},

Your {{.service}} appointment is confirmed for {{.startDate}} at {{.startTime}}.

{{if index .metaData "special_instructions"}}
Special Instructions: {{index .metaData "special_instructions"}}
{{end}}

{{if index .metaData "preparation_video"}}
Preparation Video: {{index .metaData "preparation_video"}}
{{end}}

{{if and .metaData (index .metaData "google_calendar")}}
{{if index (index .metaData "google_calendar") "video_url"}}
Video Call Link: {{index (index .metaData "google_calendar") "video_url"}}
{{end}}
{{if index (index .metaData "google_calendar") "location"}}
Location: {{index (index .metaData "google_calendar") "location"}}
{{end}}
{{end}}

We look forward to seeing you!

Troubleshooting

Common Issues

  1. Variables Not Replacing: Check spelling and case sensitivity
  2. Conditional Not Working: Verify operator usage and data types
  3. Metadata Access Errors: Use safe access patterns with existence checks
  4. Template Parsing Errors: Validate template syntax and bracket matching

Testing Your Templates

Use the interactive preview above to test your templates with sample data and verify the output matches your expectations.