obsidian_apply_template
Apply an Obsidian template to a target note, replacing placeholders like date, title, and custom variables. Specify template and target paths with optional variable overrides.
Instructions
Render a template note into a target note. Replaces {{date}}, {{title}}, {{vault}}, and custom variables.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| vault | No | Optional configured vault name. Defaults to the server default vault. | |
| templatePath | Yes | Vault-relative path. Absolute paths and traversal are rejected. | |
| targetPath | Yes | ||
| variables | No | ||
| overwrite | No |
Implementation Reference
- src/tools.ts:1007-1029 (handler)The handler implementation for obsidian_apply_template tool. It reads a template note, resolves variables ({{date}}, {{title}}, {{vault}}, and custom variables), renders the template by replacing {{...}} placeholders, and writes the result to the target path.
tool( "obsidian_apply_template", "Render a template note into a target note. Replaces {{date}}, {{title}}, {{vault}}, and custom variables.", { vault: vaultArg, templatePath: pathArg, targetPath: pathArg, variables: z.record(z.string()).optional().default({}), overwrite: z.boolean().optional().default(false), }, async (args) => { const template = await vaults.readText(args.templatePath, args.vault); const target = vaults.notePath(args.targetPath); const variables: Record<string, string> = { date: new Date().toISOString().slice(0, 10), title: path.posix.basename(target).replace(/\.md$/i, ""), vault: vaults.getVault(args.vault).name, ...args.variables, }; const rendered = template.text.replace(/\{\{\s*([A-Za-z0-9_-]+)\s*\}\}/g, (_m, key: string) => variables[key] ?? ""); return vaults.writeText(target, rendered, args.vault, { overwrite: args.overwrite }); }, ); - src/tools.ts:1007-1016 (schema)The Zod schema for obsidian_apply_template: accepts vault (optional), templatePath, targetPath, variables (record of strings), and overwrite (boolean default false).
tool( "obsidian_apply_template", "Render a template note into a target note. Replaces {{date}}, {{title}}, {{vault}}, and custom variables.", { vault: vaultArg, templatePath: pathArg, targetPath: pathArg, variables: z.record(z.string()).optional().default({}), overwrite: z.boolean().optional().default(false), }, - src/tools.ts:1007-1009 (registration)Registration of the obsidian_apply_template tool via the local tool() helper function, with name 'obsidian_apply_template' and description 'Render a template note into a target note. Replaces {{date}}, {{title}}, {{vault}}, and custom variables.'
tool( "obsidian_apply_template", "Render a template note into a target note. Replaces {{date}}, {{title}}, {{vault}}, and custom variables.",