frappe-printing-templates

Build print formats, email templates, and web page templates using Jinja. Generate PDFs and configure letter heads. Use when creating custom print layouts, email templates, or any Jinja-based rendering in Frappe.

14 stars

Best use case

frappe-printing-templates is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Build print formats, email templates, and web page templates using Jinja. Generate PDFs and configure letter heads. Use when creating custom print layouts, email templates, or any Jinja-based rendering in Frappe.

Teams using frappe-printing-templates should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/frappe-printing-templates/SKILL.md --create-dirs "https://raw.githubusercontent.com/lubusIN/agent-skills/main/skills/frappe/frappe-printing-templates/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/frappe-printing-templates/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How frappe-printing-templates Compares

Feature / Agentfrappe-printing-templatesStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Build print formats, email templates, and web page templates using Jinja. Generate PDFs and configure letter heads. Use when creating custom print layouts, email templates, or any Jinja-based rendering in Frappe.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# Frappe Printing & Templates

Create print formats, email templates, and document templates using Jinja in Frappe.

## When to use

- Creating custom print formats for documents
- Building email templates with dynamic content
- Generating PDFs from documents
- Using Jinja templating in web pages
- Configuring letter heads for branding
- Using the Print Format Builder

## Inputs required

- Target DocType for the print format
- Layout requirements (fields, tables, headers)
- Whether format is standard (version controlled) or custom (DB-stored)
- Letter Head / branding requirements
- PDF generation needs

## Procedure

### 0) Choose format type

| Type | How to Create | Version Controlled | Customizable by User |
|------|--------------|-------------------|---------------------|
| Standard | Developer Mode, saved as JSON | Yes | No |
| Print Format Builder | Drag-and-drop UI | No (DB) | Yes |
| Custom HTML (Jinja) | Type "new print format" in awesomebar | Optional | Depends |

### 1) Create a Jinja print format

Create via awesomebar → "New Print Format":
1. Set a unique name
2. Link to the target DocType
3. Set "Standard" = "No" (or "Yes" for dev mode export)
4. Check "Custom Format"
5. Set Print Format Type = "Jinja"
6. Write your Jinja HTML

```jinja
<div class="print-format">
    <h1>{{ doc.name }}</h1>
    <p><strong>{{ _("Customer") }}:</strong> {{ doc.customer }}</p>
    <p><strong>{{ _("Date") }}:</strong> {{ frappe.format_date(doc.transaction_date) }}</p>

    <table class="table table-bordered">
        <thead>
            <tr>
                <th>{{ _("Item") }}</th>
                <th>{{ _("Qty") }}</th>
                <th class="text-right">{{ _("Rate") }}</th>
                <th class="text-right">{{ _("Amount") }}</th>
            </tr>
        </thead>
        <tbody>
            {% for item in doc.items %}
            <tr>
                <td>{{ item.item_name }}</td>
                <td>{{ item.qty }}</td>
                <td class="text-right">{{ frappe.format(item.rate, {'fieldtype': 'Currency'}) }}</td>
                <td class="text-right">{{ frappe.format(item.amount, {'fieldtype': 'Currency'}) }}</td>
            </tr>
            {% endfor %}
        </tbody>
        <tfoot>
            <tr>
                <td colspan="3" class="text-right"><strong>{{ _("Total") }}</strong></td>
                <td class="text-right"><strong>{{ frappe.format(doc.grand_total, {'fieldtype': 'Currency'}) }}</strong></td>
            </tr>
        </tfoot>
    </table>

    {% if doc.terms %}
    <div class="terms">
        <h4>{{ _("Terms & Conditions") }}</h4>
        <p>{{ doc.terms }}</p>
    </div>
    {% endif %}
</div>

<style>
    .print-format { font-family: Arial, sans-serif; }
    .print-format h1 { color: #333; }
    .print-format table { width: 100%; margin-top: 20px; }
</style>
```

### 2) Use Frappe Jinja API

**Data fetching in templates:**

```jinja
{# Fetch a document #}
{% set customer = frappe.get_doc('Customer', doc.customer) %}
{{ customer.customer_name }}

{# List query (ignores permissions) #}
{% set open_orders = frappe.get_all('Sales Order',
    filters={'customer': doc.customer, 'status': 'To Deliver and Bill'},
    fields=['name', 'grand_total'],
    order_by='creation desc',
    page_length=5) %}

{# Permission-aware list query #}
{% set my_tasks = frappe.get_list('Task',
    filters={'owner': frappe.session.user}) %}

{# Single value lookup #}
{% set company_abbr = frappe.db.get_value('Company', doc.company, 'abbr') %}

{# Settings value #}
{% set timezone = frappe.db.get_single_value('System Settings', 'time_zone') %}
```

**Formatting:**

```jinja
{{ frappe.format(50000, {'fieldtype': 'Currency'}) }}
{{ frappe.format_date('2025-01-15') }}
{{ frappe.format_date(doc.posting_date) }}
```

**Session and context:**

```jinja
{{ frappe.session.user }}
{{ frappe.get_fullname() }}
{{ frappe.lang }}
{{ _("Translatable string") }}
```

**URLs:**

```jinja
<a href="{{ frappe.get_url() }}/app/sales-order/{{ doc.name }}">View Order</a>
```

### 3) Build email templates

```jinja
Dear {{ doc.customer_name }},

Your order {{ doc.name }} has been confirmed.

Items:
{% for item in doc.items %}
- {{ item.item_name }} x {{ item.qty }}
{% endfor %}

Total: {{ frappe.format(doc.grand_total, {'fieldtype': 'Currency'}) }}

Thank you,
{{ frappe.get_fullname() }}
```

### 4) Generate PDFs programmatically

```python
import frappe

# Generate PDF
pdf_content = frappe.get_print(
    doctype="Sales Invoice",
    name="SINV-001",
    print_format="Custom Invoice",
    as_pdf=True
)

# Attach PDF to document
frappe.attach_print(
    doctype="Sales Invoice",
    name="SINV-001",
    print_format="Custom Invoice",
    file_name="invoice.pdf"
)

# Send with email
frappe.sendmail(
    recipients=["customer@example.com"],
    subject="Your Invoice",
    message="Please find attached your invoice.",
    attachments=[{
        "fname": "invoice.pdf",
        "fcontent": pdf_content
    }]
)
```

### 5) Configure Letter Head

1. Navigate to Letter Head list → New
2. Upload company logo and header image
3. Set as default for the company
4. Letter Head appears automatically on print formats

### 6) Use Jinja filters

```jinja
{{ doc.customer_name|upper }}        {# UPPERCASE #}
{{ doc.notes|truncate(100) }}        {# Truncate text #}
{{ doc.description|striptags }}      {# Remove HTML #}
{{ doc.html_content|safe }}          {# Render raw HTML (trusted only!) #}
{{ items|length }}                   {# Count items #}
{{ items|first }}                    {# First item #}
{{ names|join(', ') }}               {# Join list #}
{{ amount|round(2) }}               {# Round number #}
{{ value|default('N/A') }}          {# Default if undefined #}
{{ data|tojson }}                    {# Convert to JSON #}
```

### 7) Template inheritance and macros

```jinja
{# macros/fields.html #}
{% macro field_row(label, value) %}
<tr>
    <td class="label"><strong>{{ _(label) }}</strong></td>
    <td>{{ value }}</td>
</tr>
{% endmacro %}

{# In print format #}
{% from "macros/fields.html" import field_row %}
<table>
    {{ field_row("Customer", doc.customer_name) }}
    {{ field_row("Date", frappe.format_date(doc.posting_date)) }}
    {{ field_row("Total", frappe.format(doc.grand_total, {'fieldtype': 'Currency'})) }}
</table>
```

## Verification

- [ ] Print format renders correctly in Print View
- [ ] All fields display with proper formatting
- [ ] PDF generation works without errors
- [ ] Email templates render with correct data
- [ ] Letter Head appears on printed documents
- [ ] Translations work in templates (`_()`)
- [ ] No XSS risks from unescaped content

## Failure modes / debugging

- **Template syntax error**: Check Jinja delimiters (`{{ }}`, `{% %}`); look for unclosed blocks
- **Field not rendering**: Verify field name matches DocType schema; check child table access pattern
- **PDF generation fails**: Check wkhtmltopdf installation; verify print format Jinja is valid
- **Styling issues in PDF**: Use inline styles; avoid complex CSS; test with Print View first
- **Permission error in template**: Use `frappe.get_all` (no permission check) vs `frappe.get_list`

## Escalation

- For app-level hooks and structure → `frappe-app-development`
- For DocType schema questions → `frappe-doctype-development`

## References

- [references/jinja.md](references/jinja.md) — Jinja templating and Frappe Jinja API
- [references/printing.md](references/printing.md) — Print formats and PDF generation

## Guardrails

- **Test with actual data**: Always preview with real documents; edge cases break templates
- **Handle missing fields gracefully**: Use `{{ doc.field or '' }}` or `{% if doc.field %}`
- **Use `get_url()` for images**: Never hardcode URLs; use `{{ frappe.utils.get_url() }}/files/...`
- **Escape user content**: Use `{{ value | e }}` for user-generated content to prevent XSS
- **Keep styling inline**: PDF generators don't support external CSS; use inline `style` attributes

## Common Mistakes

| Mistake | Why It Fails | Fix |
|---------|--------------|-----|
| Wrong Jinja syntax | Template error, blank output | Use `{{ }}` for output, `{% %}` for logic; check closing tags |
| Missing filters | Raw data displayed | Use `frappe.format()` or `frappe.format_date()` for formatting |
| Hardcoded URLs | Images/links break across sites | Use `{{ frappe.utils.get_url() }}` for absolute URLs |
| Accessing child table wrong | Empty or error | Use `{% for item in doc.items %}` not `doc.child_table_name` |
| Complex CSS in print format | Styling lost in PDF | Use inline styles, simple layouts, `<table>` for structure |
| Not handling None values | `'None'` string in output | Use `{{ value or '' }}` or `{% if value %}` |

Related Skills

frappe-web-forms

14
from lubusIN/agent-skills

Build public-facing web forms for data collection without Desk access. Use when creating customer submission forms, feedback forms, or self-service portals with Frappe Web Forms.

frappe-ui-patterns

14
from lubusIN/agent-skills

UI/UX patterns and guidelines derived from official Frappe apps (CRM, Helpdesk, HRMS). Use when designing interfaces for custom Frappe applications to ensure consistency with the ecosystem.

frappe-testing

14
from lubusIN/agent-skills

Write and run tests for Frappe apps including unit tests, integration tests, and UI tests. Use when adding test coverage, debugging test failures, or setting up CI for Frappe projects.

frappe-router

14
from lubusIN/agent-skills

Route to the appropriate Frappe skill based on task type. Use as the entry point when working on Frappe projects to determine which specialized skill to apply.

frappe-reports

14
from lubusIN/agent-skills

Create reports in Frappe including Report Builder, Query Reports (SQL), and Script Reports (Python + JS). Use when building data analysis views, dashboards, or custom reporting features.

frappe-project-triage

14
from lubusIN/agent-skills

Detect Frappe project type, installed apps, version, and tooling. Use as the first step when working on any Frappe/ERPNext codebase to understand the project structure before making changes.

frappe-manager

14
from lubusIN/agent-skills

Use Frappe Manager (FM) for Docker-based development and testing environments. Use when setting up local dev, running isolated tests, or managing agent-driven Frappe development workflows.

frappe-frontend-development

14
from lubusIN/agent-skills

Build modern Vue 3 frontend apps using Frappe UI with components, data fetching, and portal pages. Use when creating custom frontends, SPAs, or portal interfaces for Frappe applications.

frappe-enterprise-patterns

14
from lubusIN/agent-skills

Production-grade architectural patterns for building enterprise Frappe apps like CRM, Helpdesk, and HRMS. Use when designing complex multi-entity systems with workflows, SLAs, and integrations.

frappe-doctype-development

14
from lubusIN/agent-skills

Create and modify Frappe DocTypes including schema design, controllers, child tables, and customization. Use when building data models, adding fields, or implementing document lifecycle logic.

frappe-desk-customization

14
from lubusIN/agent-skills

Customize Frappe Desk UI with form scripts, list view scripts, report scripts, dialogs, and client-side JavaScript APIs. Use when building interactive Desk experiences, adding custom buttons, or scripting form behavior.

frappe-app-development

14
from lubusIN/agent-skills

Scaffold and architect custom Frappe apps including app structure, hooks, background jobs, service layers, and production hardening. Use when creating new apps, setting up app architecture, or implementing cross-cutting patterns like caching, logging, and error handling.