MindStudio Docs
  • Get Started
    • Overview
    • MindStudio Chrome Extension
    • Quickstart Guide
    • What is an AI Agent?
    • AI Agent Use Cases
  • Free vs. Paid AI Agents
  • Building AI Agents
    • Editor Overview
    • Workflow Generator
    • Writing Prompts
      • Templating
    • AI Models
    • Variables
      • Working with JSON
      • Using Handlebars Templating
    • Dynamic Variables
    • Data Sources
    • Automations
      • Start Block
      • Generate Text Block
      • Generate Image Block
      • Generate Chart Block
      • Generate Asset Block
      • Display Content Block
      • Text to Speech Block
      • Analyze Image Block
      • User Input Block
      • User Context Block
      • Query Data Block
      • Run Function Block
      • Scrape URL Block
      • Extract Text from File Block
      • Post to Slack Block
      • Menu Block
      • Logic Block
      • Checkpoint Block
      • Jump Block
      • Run Workflow Block
      • Terminator Block
    • Integrations
      • Search Bluesky Posts
      • Scrape Facebook Page
      • Scrape Meta Threads Profile
      • Scrape Instagram Comments
      • Scrape Instagram Mentions
      • Scrape Instagram Posts
      • Scrape Instagram Profile
      • Scrape Instagram Reels
      • Create LinkedIn Post
      • Create X Post
      • Search X Posts
      • Search Google
      • Search Google Images
      • Search Google Trends
      • Search Google News
      • Create Google Doc
      • Fetch Google Doc
      • Update Google Doc
      • Create Google Sheet
      • Fetch Google Sheet
      • Update Google Sheet
      • Enrich Company via Domain
      • Find Contact Email for Website
      • Find Email
      • Verify Email
      • Enrich Person via Email
      • Fetch YouTube Captions
      • Fetch YouTube Channel
      • Fetch YouTube Comments
      • Fetch YouTube Video
      • Search YouTube
      • Search YouTube Trends
      • Create Notion Page
      • Update Notion Page
      • Apify
      • Run Scenario
      • Post to Slack
      • HTTP Request
      • Run Node
      • Create Contact
      • Add Note
      • Send Email
      • Send SMS
    • Publishing & Versioning
  • Embedding AI Agents
  • Using Webhooks
  • Workspace Management
    • Workspace Overview
    • Workspace Settings
    • Usage Explorer
    • Billing Settings
    • Account Settings
    • Team Settings & Access Controls
  • Test & Evaluate
    • Testing Suite Overview
    • Evaluations
    • Profiler
    • Debugger
  • Integration Guides
    • Zapier + MindStudio
    • Make.com + MindStudio
    • n8n + MindStudio
  • Developers
    • API Reference
    • NPM Package
    • Custom Workflow Functions
  • Additional Resources
    • Glossary
    • Allowing Access to Mindstudio From Your Network
  • Solutions
    • MindStudio Solutions Partners
    • MindStudio For Developers
    • MindStudio for Enterprises
Powered by GitBook
On this page
  • Overview
  • Conditional Logic
  • Special Handlebars Methods in MindStudio
Export as PDF
  1. Building AI Agents
  2. Variables

Using Handlebars Templating

Learn how to use Handlebars methods in MindStudio

Last updated 1 day ago

Overview

MindStudio leverages the to make working with variables intuitive and powerful. Handlebars allows you to include, manipulate, and conditionally render data directly in your prompts, outputs, and logic.


Conditional Logic

Handlebars supports if-else logic for dynamic outputs:

{{#if userName}}
Hello, {{userName}}! How can we assist you today?
{{else}}
Hello! Please log in to get started.
{{/if}}

For a full list of expressions, see .


Special Handlebars Methods in MindStudio

In addition to standard Handlebars features, MindStudio introduces special methods for advanced functionality:

{{json varName}}

Converts a JSON object into a string format.

Example:

If userProfile contains:

{
    "name": "John",
    "age": 30
}

Usage:

{{json userProfile}}

Output:

{"name":"John","age":30}

{{sample varName number token}}

Extracts a portion of the variable's content based on specified parameters.

  • Parameters:

    • varName: The variable to sample.

    • number: The number of items (e.g., lines, words, or letters). If negative, starts from the end.

    • token: The type of unit to extract (line, word, or letter).

  • Examples:

    • Extract the first 5 words:

      {{sample textVar 5 "word"}}
    • Extract the last 3 lines:

      {{sample textVar -3 "line"}}
    • Extract the first 10 letters:

      {{sample textVar 10 "letter"}}

{{#if condition}}

Converts a conditional block that renders content only when the condition is true.

Example:

If isLoggedIn is true

Usage:

{{#if isLoggedIn}}
  Welcome back!
{{/if}}

Output:

Welcome back!

{{#unless condition}}

Converts a conditional block that renders content only when the condition is false.

Example:

If isLoggedIn is false

Usage:

{{#unless isLoggedIn}}
  Please sign in.
{{/unless}}

Output:

Please sign in.

{{#each array}}

Iterates over an array or object and renders the block for every item.

Example:

If items contains:

["Apple", "Banana", "Cherry"]

Usage:

{{#each items}}
  {{this}}
{{/each}}

Output:

opyApple
Banana
Cherry

{{#with object}}

Changes the evaluation context to the provided object for the enclosed block.

Example:

If user contains:

{ "name": "Alice", "age": 25 }

Usage:

{{#with user}}
  {{name}} is {{age}} years old.
{{/with}}

Output:

Alice is 25 years old.

{{lookup object key}}

Dynamically looks up a property from an object using a key.

Example:

If user contains:

{ "name": "Alice", "role": "admin" }

Usage:

{{lookup user "role"}}

Output:

admin

{{log value}}

Logs a value to the console for debugging purposes.

Example:

If debugData contains:

{"error": "Not Found"}

Usage:

{{log debugData}}

Output:

(Check the browser console for the logged value)


{{get varName "property"}}

Retrieves a nested property using a JSONPath expression from a JSON object.

Example:

If userDatacontains:

{
  "name": "Alice",
  "contact": { "email": "alice@example.com" }
}

Usage:

{{get userData "$.contact.email"}}

Output:

alice@example.com

{{add num increment}}

Adds a numeric increment to a given number.

Example:

If num is:

5

Usage:

{{add 5 3}}

Output:

8

{{subtract num decrement}}

Subtracts a numeric value from a given number.

Example:

If num is:

10

Usage:

{{subtract 10 4}}

Output:

6

{{multiply value multiplier}}

Multiplies two numbers.

Example:

If value is:

2

Usage:

{{multiply 2 5}}

Output:

10

{{divide dividend divisor}}

Divides one number by another.

Example:

If dividend is:

10

Usage:

{{divide 10 2}}

Output:

5

{{eq var1 var2}}

Checks if two values are equal using the double-equals operator.

Example:

If var1 contains:

5

and var2 contains:

"5"

Usage:

{{eq 5 "5"}}

Output:

true

{{gt value1 value2}}

Checks if the first value is greater than the second value.

Example:

If value1 is:

10

and value2 is:

5

Usage:

{{gt 10 5}}

Output:

true

{{gte value1 value2}}

Checks if the first value is greater than or equal to the second value.

Example:

If value1 is:

10

and value2 is:

10

Usage:

{{gte 10 10}}

Output:

true

{{lt value1 value2}}

Checks if the first value is less than the second value.

Example:

If value1 is:

5

and value2 is:

10

Usage:

{{lt 5 10}}

Output:

true

{{lte value1 value2}}

Checks if the first value is less than or equal to the second value.

Example:

If value1 is:

5

and value2 is:

5

Usage:

{{lte 5 5}}

Output:

true

{{isEmpty varName}}

Evaluates whether a variable is empty (null, undefined, an empty string, an empty array, or an empty object).

Example:

If data contains:

""

Usage:

{{isEmpty data}}

Output:

true

{{length varName}}

Returns the length of an array or a string. Returns "NaN" if the variable is not an array or string.

Example:

If list contains:

["a", "b", "c"]

Usage:

{{length list}}

Output:

3

{{markdown varName}}

Converts a Markdown-formatted string into HTML.

Example:

If markdownText contains:

# Hello World
This is **bold** text.

Usage:

{{markdown markdownText}}

Output:

<h1>Hello World</h1>
<p>This is <strong>bold</strong> text.</p>

{{formattedNumber number fractionDigits}}

Formats a number using locale‑specific formatting with a fixed number of fractional digits.

Example:

If amount is:

1234.567

Usage:

{{formattedNumber 1234.567 2}}

Output:

1,234.57

{{abbreviatedNumber number fractionDigits}}

Formats a number into a compact, abbreviated notation (e.g., 1K, 1M) with a specified number of fractional digits.

Example:

If amount is:

1500

Usage:

{{abbreviatedNumber 1500 1}}

Output:

1.5k

{{date varName format}}

Formats a date string according to the specified format. Supports both custom formats (e.g., "YYYY-MM-DD") and relative keywords like "fromNow" or "toNow".

Example:

If dateString contains:

2020-01-01T00:00:00Z

Usage:

{{date dateString "YYYY-MM-DD"}}

Output:

2020-01-01
Handlebars templating language
Handlebars Documentation