Home/Tools/@tpmjs/tools-template-render

templateRenderTool

@tpmjs/tools-template-render

Render mustache-style templates with data. Supports {{variable}} syntax and tracks which variables were used and which were defined but unused. Optionally disable HTML escaping.

Official
data
v0.1.0
MIT

Interactive Playground

Test @tpmjs/tools-template-render (templateRenderTool) with AI-powered execution

0/2000 characters

Installation & Usage

Install this tool and use it with the AI SDK

1. Install the package

npm install @tpmjs/tools-template-render
pnpm add @tpmjs/tools-template-render
yarn add @tpmjs/tools-template-render
bun add @tpmjs/tools-template-render
deno add npm:@tpmjs/tools-template-render

2. Import the tool

import { templateRenderTool } from '@tpmjs/tools-template-render';

3. Use with AI SDK

import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import { templateRenderTool } from '@tpmjs/tools-template-render';

const result = await generateText({
  model: openai('gpt-4o'),
  tools: { templateRenderTool },
  prompt: 'Your prompt here...',
});

console.log(result.text);

Parameters

Available configuration options

Auto-extracted
template
Required
Type: string

The mustache-style template string with {{variable}} placeholders

data
Required
Type: object

Data object to substitute into the template

options
Optional
Type: object

Optional rendering settings

Schema extracted: 1/1/2026, 8:18:42 AM

README

@tpmjs/tools-template-render

Render mustache-style templates with variable tracking.

Installation

npm install @tpmjs/tools-template-render

Usage

import { templateRenderTool } from '@tpmjs/tools-template-render';

const result = await templateRenderTool.execute({
  template: 'Hello {{name}}! Your score is {{score}}.',
  data: {
    name: 'Alice',
    score: 95,
    unused: 'extra data'
  }
});

console.log(result.rendered);
// => "Hello Alice! Your score is 95."

console.log(result.variablesUsed);
// => ["name", "score"]

console.log(result.unusedVariables);
// => ["unused"]

Options

// Disable HTML escaping
const result = await templateRenderTool.execute({
  template: 'Content: {{html}}',
  data: { html: '<strong>Bold</strong>' },
  options: { escape: false }
});

Features

  • Mustache syntax: Uses standard {{variable}} placeholders
  • Variable tracking: Reports which variables were used and which were provided but unused
  • HTML escaping: Automatically escapes HTML by default (can be disabled)
  • Nested data: Supports nested object access with dot notation

License

MIT

Statistics

Downloads/month

0

Quality Score

0%

Bundle Size

NPM Keywords

tpmjs
template
mustache
render
data

Maintainers

thomasdavis(thomasalwyndavis@gmail.com)

Frameworks

vercel-ai