---
name: email-template-rendering
description: |
  Fix for Handlebars email template rendering issues in the notifications app.
  Use when: "Missing helper", template variables not rendering, partials not found,
  HTML escaping issues in emails. Only loads when working in apps/notifications/.
author: Memory Forge
version: 1.0.0
date: 2025-01-28
---

# Email Template Rendering Fixes

## Problem

Handlebars templates for email notifications fail to render correctly, showing raw variables, missing helpers, or escaped HTML.

## Trigger Conditions

- Error: `Missing helper: "formatDate"`
- Variables showing as `{{variable}}` in sent emails
- Error: `The partial X could not be found`
- HTML appearing escaped (`&lt;div&gt;` instead of `<div>`)
- Working in `apps/notifications/` directory

## Solution

### Issue 1: Missing Helpers

Register custom helpers before compiling templates:

```typescript
import Handlebars from 'handlebars';

// Register helpers BEFORE compiling templates
Handlebars.registerHelper('formatDate', (date: Date, format: string) => {
  return dayjs(date).format(format);
});

Handlebars.registerHelper('formatCurrency', (amount: number, currency: string) => {
  return new Intl.NumberFormat('en-US', {
    style: 'currency',
    currency: currency || 'USD',
  }).format(amount);
});

// Now compile
const template = Handlebars.compile(templateSource);
```

### Issue 2: HTML Escaping

Use triple braces for unescaped HTML:

```handlebars
{{! WRONG - HTML will be escaped }}
<div>{{htmlContent}}</div>

{{! CORRECT - HTML renders as-is }}
<div>{{{htmlContent}}}</div>
```

Or use `SafeString` in helpers:

```typescript
Handlebars.registerHelper('renderHtml', (html: string) => {
  return new Handlebars.SafeString(html);
});
```

### Issue 3: Partials Not Found

Register partials before use:

```typescript
// Register partial
Handlebars.registerPartial('header', headerTemplateSource);
Handlebars.registerPartial('footer', footerTemplateSource);

// Use in template
// {{> header}}
// ... content ...
// {{> footer}}
```

### Issue 4: Async Data in Templates

Handlebars is synchronous. Resolve all data before rendering:

```typescript
// WRONG
const template = Handlebars.compile(source);
const html = template({ user: await getUser() }); // ❌ Promise in template

// CORRECT
const user = await getUser();
const orders = await getOrders(user.id);
const template = Handlebars.compile(source);
const html = template({ user, orders }); // ✅ Resolved data
```

## Verification

1. Compile template without errors
2. Render with sample data
3. Check output HTML is correct
4. Send test email and verify in email client

## Notes

- This skill only loads when working in `apps/notifications/`
- Always precompile templates in production for performance
- Test emails in multiple clients (Gmail, Outlook, Apple Mail)
- Use inline CSS for email compatibility


---
Source attribution: javicasper
Original project: https://github.com/javicasper/memory-forge/blob/493bd289212ecb1f0b33937df3ef0b046d088352/examples/monorepo/apps/notifications/.claude/skills/email-template-rendering/SKILL.md
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Dave AI.

## Upstream license notice

MIT License

Copyright (c) 2025 Memory Forge Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Dave AI resource metadata

Creator / publisher: javicasper
Original project: https://github.com/javicasper/memory-forge/blob/493bd289212ecb1f0b33937df3ef0b046d088352/examples/monorepo/apps/notifications/.claude/skills/email-template-rendering/SKILL.md
Attribution basis: Recovered original package and original project license at a pinned revision

Fields of work: Marketing
Roles: Content Marketer, Email Marketer
Specialties: API
Tools: Tool not specified
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: a6a8e5523d48a4124726ccf983ab59a029912df51495e8fb72dfc9f3797860c7
Metadata reviewed: 2026-10-27
This metadata supersedes earlier Dave AI catalog attribution. Original instruction and supporting files are preserved.
