template-engine
БесплатноБез исполняемых скриптовНе проверенAuto-fill document templates with data. Use when a user asks to create a mail merge, fill templates with data, generate documents from a template, populate…
от TerminalSkills★ 221 звезда на GitHubОб этом скилле
Template Engine
Overview
Auto-fill document templates with data from spreadsheets, databases, or JSON. Supports mail merge for any format: DOCX, PDF, HTML, Markdown, and plain text. Generate hundreds of personalized documents from a single template and data source.
Instructions
When a user needs template-based document generation, determine the format and approach:
Task A: DOCX template filling with python-docx-template
- Install the library:
pip install docxtpl openpyxl
Create a DOCX template with Jinja2 placeholders:
- Use
{{ variable }}for simple values - Use
{% for item in items %}...{% endfor %}for loops - Use
{% if condition %}...{% endif %}for conditionals - To repeat or hide a whole paragraph or table row, put the tag alone in it with a
portrprefix:{%p for item in items %}...{%p endfor %},{%tr for row in rows %}...{%tr endfor %}. Plain{% %}inside a paragraph leaves empty paragraphs behind - Write each tag in one go in Word (type or paste as plain text); Word splits formatted text into runs and can break a tag in half
- Use
Fill the template:
from docxtpl import DocxTemplate
import json
def fill_docx_template(template_path: str, data: dict, output_path: str):
doc = DocxTemplate(template_path)
doc.render(data, autoescape=True) # escapes &, <, > so "Smith & Sons" does not corrupt the XML
doc.save(output_path)
# Single document
data = {
"client_name": "Northwind Traders",
"date": "2026-10-13",
"items": [
{"description": "Consulting", "amount": 5000},
{"description": "Development", "amount": 12000},
],
"total": 17000
}
fill_docx_template("invoice_template.docx", data, "invoice_northwind.docx")
- Bulk generation from CSV:
import csv
import re
from docxtpl import DocxTemplate
def mail_merge_docx(template_path: str, csv_path: str, output_dir: str):
with open(csv_path, newline="", encoding="utf-8") as f:
rows = list(csv.DictReader(f))
for i, row in enumerate(rows):
doc = DocxTemplate(template_path)
doc.render(row, autoescape=True)
safe_name = re.sub(r"[^A-Za-z0-9_-]+", "_", row.get("name") or str(i))
filename = f"{output_dir}/{safe_name}.docx"
doc.save(filename)
print(f"Generated: {filename}")
print(f"Created {len(rows)} documents")
mail_merge_docx("letter_template.docx", "contacts.csv", "./output")
Task B: HTML/Markdown templates with Jinja2
from jinja2 import Environment, FileSystemLoader, select_autoescape
import csv
env = Environment(
loader=FileSystemLoader("./templates"),
autoescape=select_autoescape(["html", "xml"]), # off by default in Jinja2
)
template = env.get_template("report.html")
with open("data.csv") as f:
rows = list(csv.DictReader(f))
for row in rows:
html = template.render(**row)
output_file = f"./output/{row['id']}_report.html"
with open(output_file, "w") as out:
out.write(html)
Example Jinja2 template (templates/report.html):
<!DOCTYPE html>
<html>
<head><title>Report for {{ company_name }}</title></head>
<body>
<h1>Monthly Report: {{ company_name }}</h1>
<p>Period: {{ start_date }} to {{ end_date }}</p>
<table>
<tr><th>Metric</th><th>Value</th></tr>
{% for metric in metrics %}
<tr><td>{{ metric.name }}</td><td>{{ metric.value }}</td></tr>
{% endfor %}
</table>
</body>
</html>
Task C: PDF generation from templates
Render HTML with Jinja2, then convert it with WeasyPrint (pip install weasyprint; it needs the Pango library, which is a system package on Linux and macOS; see the WeasyPrint install docs):
from jinja2 import Environment, FileSystemLoader, select_autoescape
from weasyprint import HTML
env = Environment(loader=FileSystemLoader("./templates"),
autoescape=select_autoescape(["html", "xml"]))
def generate_pdf(template_name: str, data: dict, output: str):
html = env.get_template(template_name).render(**data)
HTML(string=html, base_url="./templates").write_pdf(output)
Set page size and margins in the template's CSS (@page { size: A4; margin: 2cm; }). WeasyPrint does not run JavaScript; if the page needs a real browser (charts, JS layout), render with a headless Chromium tool such as Playwright's page.pdf() instead. Avoid pdfkit/wkhtmltopdf: the wkhtmltopdf project was archived in 2023.
Task D: Plain text templates (emails, notifications)
from string import Template
import csv
def text_mail_merge(template_str: str, csv_path: str) -> list[str]:
template = Template(template_str)
results = []
with open(csv_path) as f:
for row in csv.DictReader(f):
results.append(template.safe_substitute(row))
return results
# Usage
email_template = """Dear $name,
Thank you for your order #$order_id placed on $date.
Your total is $$amount.
Best regards,
The Team"""
Установить template-engine в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл template-engine?
Auto-fill document templates with data. Use when a user asks to create a mail merge, fill templates with data, generate documents from a template, populate placeholders, bulk generate letters or invoices, or auto-fill forms from a spreadsheet. Supports any document format including DOCX, PDF, HTML, and plain text.
Как установить скилл template-engine?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл template-engine запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
docx
Use this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include…
от AnthropicUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple…
от Anthropicxlsx
Use this skill any time a spreadsheet file is the primary input or output. This means any task where the user wants to: open, read, edit, or fix an existing…
от Anthropicpptx
Use this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or…
от Anthropic