Loading...
Loading...
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.
npx skill4agent add lubusin/agent-skills frappe-printing-templates| 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 |
<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>{# 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') %}{{ frappe.format(50000, {'fieldtype': 'Currency'}) }}
{{ frappe.format_date('2025-01-15') }}
{{ frappe.format_date(doc.posting_date) }}{{ frappe.session.user }}
{{ frappe.get_fullname() }}
{{ frappe.lang }}
{{ _("Translatable string") }}<a href="{{ frappe.get_url() }}/app/sales-order/{{ doc.name }}">View Order</a>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() }}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
}]
){{ 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 #}{# 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>_(){{ }}{% %}frappe.get_allfrappe.get_listfrappe-app-developmentfrappe-doctype-development{{ doc.field or '' }}{% if doc.field %}get_url(){{ frappe.utils.get_url() }}/files/...{{ value | e }}style| Mistake | Why It Fails | Fix |
|---|---|---|
| Wrong Jinja syntax | Template error, blank output | Use |
| Missing filters | Raw data displayed | Use |
| Hardcoded URLs | Images/links break across sites | Use |
| Accessing child table wrong | Empty or error | Use |
| Complex CSS in print format | Styling lost in PDF | Use inline styles, simple layouts, |
| Not handling None values | | Use |