# Handlebars Template Compiler MCP

> Handlebars Template Compiler uses the industry-standard Handlebars engine to flawlessly compile dynamic templates. Instead of asking your AI client to manually search and replace variables or process complex HTML logic, this MCP compiles raw Handlebars code against structured data payloads. It handles loops (like product lists) and conditional statements, guaranteeing production-ready email content and web payload structures every time.

## Overview
- **Category:** loved-by-devs
- **Price:** Free
- **Tags:** handlebars, template, email, html, marketing

## Description

Drafting marketing emails or building dynamic web pages often means dealing with template languages like Handlebars. These templates contain placeholders—things like `{{customer_name}}` or logic blocks (`{{#if is_premium}}`). When an AI agent tries to process this, it frequently fails, deleting parts of the HTML or misinterpreting complex loops. This MCP fixes that problem completely. It uses a dedicated compiler engine to merge your raw template code and structured data payloads exactly how they should be. You provide the skeleton (the template) and the ingredients (the JSON data), and we give you perfect, functional HTML output. Because this logic is handled by an established standard, not fuzzy AI inference, you get reliable results for everything from welcome emails to complex product list layouts. When your agent connects to Vinkius, it gains access to this compiler, ensuring that template rendering is always accurate.

## Tools

### compile_template
This tool compiles Handlebars templates by taking a raw template string and a JSON data string to generate final HTML content, correctly handling loops and conditionals.

## Prompt Examples

**Prompt:** 
```
Compile the template `Welcome {{name}}!` using this data: `{"name":"Alice"}`.
```

**Response:** 
```
Compiled Template Result: Successfully compiled.
```

**Prompt:** 
```
Inject this CRM product list JSON into my Handlebars marketing email.
```

**Response:** 
```
Compiled Template Result: Output generated.
```

**Prompt:** 
```
Render this HTML snippet replacing the `{{url}}` variable.
```

**Response:** 
```
Compiled Template Result: Success.
```

## Capabilities

### Compile Templates
The MCP takes a raw Handlebars template string and a JSON data string to generate finished HTML or text payloads.

### Handle Conditional Logic
It processes complex logic blocks, such as showing content only if a user has a specific status, using the `{{#if}}` syntax.

### Iterate Over Data Lists
The MCP loops through arrays of data (like product lists) to generate repeatable HTML structures using the `{{#each}}` syntax.

## Use Cases

### Building a Product Showcase Email
A marketer needs to send an email that shows 3-5 recommended products based on user data. Instead of asking the agent to manually format HTML loops, they use this MCP's `compile_template` tool. They pass the product list JSON and the template containing `{{#each}}`, and the final, correct HTML is generated instantly.

### Creating Dynamic Welcome Pages
A developer needs a landing page that shows different content blocks based on whether the user subscribed via 'Trial' or 'Paid'. They use `compile_template` to compile a template with an `{{#if}}` block, feeding it the user status data from JSON. The result is perfectly structured HTML.

### Generating Customized Onboarding Payloads
An Ops Specialist needs to generate personalized onboarding payloads for new hires. They use this MCP to feed a template with placeholders like `{{department}}` and `{{manager_name}}`, ensuring the final data payload is perfectly structured before passing it to the main application.

### Processing Variable Product Feeds
A technical writer wants to write an email that includes a list of related items. They use `compile_template` with the product feed JSON and the loop logic, ensuring that every single item in the source data gets its own correctly formatted HTML card.

## Benefits

- Flawless template compilation: You stop worrying about variable replacement failures. The `compile_template` tool uses the industry-standard Handlebars engine to guarantee placeholders resolve correctly.
- Reliable logic handling: It processes complex features like looping through product arrays (`{{#each}}`) and showing content conditionally (`{{#if}}`), turning raw JSON into solid HTML structure.
- Guaranteed output format: This MCP doesn't guess; it compiles. You get clean, production-ready code for marketing emails or data payloads that will actually work in the destination system.
- Fewer debugging headaches: Since template logic is handled by a dedicated compiler, you spend less time fixing syntax errors and more time writing good copy.
- Handles structured complexity: It easily takes large JSON objects—like an entire product catalog—and injects them into templates meant for individual items.

## How It Works

The bottom line is you stop relying on your AI agent's ability to write code and start using a dedicated tool that guarantees perfect compilation results every time.

1. You pass two pieces of information: your raw Handlebars template containing placeholders, and a separate JSON string that holds all the data (names, prices, etc.).
2. The MCP runs this input through the established Handlebars engine, which correctly maps the JSON values into the template structure.
3. You get back clean, final HTML or text content ready to be used in an email client or web payload.

## Frequently Asked Questions

**How do I use Handlebars Template Compiler with product data?**
You pass two inputs: your template string and a JSON array containing all the products. The `compile_template` tool uses the `{{#each}}` syntax to iterate over every item, generating repeatable HTML for your list.

**Can Handlebars Template Compiler handle simple variable replacement?**
Yes, it handles that, but it's designed for more. It uses the `compile_template` function to correctly replace placeholders like `{{name}}`, even if they are nested within complex logic blocks.

**What is required in the JSON data for compile_template?**
The JSON must contain all the data points referenced in your template. For example, if your template uses `{{price}}`, the associated JSON object needs a 'price' key.

**Does Handlebars Template Compiler only work for emails?**
No. While excellent for marketing emails, it compiles any standard Handlebars template. You can use it to generate payloads or structured HTML for web components too.

**Is this better than just asking my AI client to do the compilation?**
Absolutely. This MCP uses an established engine; your agent uses pattern matching. Using `compile_template` prevents the common failures and hallucination that happen when relying solely on LLM inference for code execution.