$npx -y skills add Impertio-Studio/Frappe_Claude_Skill_Package --skill frappe-impl-jinjaUse when building Jinja templates in Frappe: Print Formats, Email Templates, Notification templates, Portal Pages, and custom Jinja methods. Covers template creation workflows, child table handling, conditional sections, styling, multi-language support, and debugging. Prevents N+
| 1 | # Frappe Jinja Templates Implementation Workflow |
| 2 | |
| 3 | Step-by-step workflows for building Jinja templates. For syntax reference, see `frappe-syntax-jinja`. |
| 4 | |
| 5 | **Version**: v14/v15/v16 (V16 Chrome PDF noted) |
| 6 | |
| 7 | --- |
| 8 | |
| 9 | ## Master Decision: What Are You Creating? |
| 10 | |
| 11 | ``` |
| 12 | WHAT IS YOUR OUTPUT? |
| 13 | │ |
| 14 | ├─► Printable PDF (invoice, PO, report)? |
| 15 | │ ├─► Standard DocType → Print Format (Jinja) |
| 16 | │ └─► Query/Script Report → Report Print Format (JAVASCRIPT!) |
| 17 | │ ⚠️ Uses {%= %} NOT {{ }} |
| 18 | │ |
| 19 | ├─► Automated email with dynamic content? |
| 20 | │ └─► Email Template (Jinja, linked to DocType) |
| 21 | │ |
| 22 | ├─► System notification? |
| 23 | │ └─► Notification (Setup > Notification, uses Jinja) |
| 24 | │ |
| 25 | ├─► Customer-facing web page? |
| 26 | │ └─► Portal Page (myapp/www/*.html + *.py) |
| 27 | │ |
| 28 | └─► Reusable template functions/filters? |
| 29 | └─► Custom jenv methods in hooks.py |
| 30 | ``` |
| 31 | |
| 32 | --- |
| 33 | |
| 34 | ## Workflow 1: Create a Print Format |
| 35 | |
| 36 | ### Step 1: Create via UI |
| 37 | |
| 38 | ``` |
| 39 | Setup > Printing > Print Format > New |
| 40 | - Name: My Invoice Format |
| 41 | - DocType: Sales Invoice |
| 42 | - Module: Accounts |
| 43 | - Standard: No (custom) |
| 44 | - Print Format Type: Jinja |
| 45 | ``` |
| 46 | |
| 47 | ### Step 2: Write the Template |
| 48 | |
| 49 | ```jinja |
| 50 | <style> |
| 51 | .print-format { font-family: Arial, sans-serif; font-size: 11px; } |
| 52 | .header { margin-bottom: 20px; } |
| 53 | .table { width: 100%; border-collapse: collapse; margin: 20px 0; } |
| 54 | .table th, .table td { border: 1px solid #ddd; padding: 8px; } |
| 55 | .table th { background: #f0f0f0; } |
| 56 | .text-right { text-align: right; } |
| 57 | </style> |
| 58 | |
| 59 | <div class="header"> |
| 60 | <h1>{{ doc.select_print_heading or _("Invoice") }}</h1> |
| 61 | <p><strong>{{ doc.name }}</strong> | |
| 62 | {{ doc.get_formatted("posting_date") }}</p> |
| 63 | </div> |
| 64 | |
| 65 | <p><strong>{{ doc.customer_name }}</strong></p> |
| 66 | {% if doc.address_display %} |
| 67 | <p>{{ doc.address_display | safe }}</p> |
| 68 | {% endif %} |
| 69 | |
| 70 | <table class="table"> |
| 71 | <thead> |
| 72 | <tr> |
| 73 | <th>#</th> |
| 74 | <th>{{ _("Item") }}</th> |
| 75 | <th class="text-right">{{ _("Qty") }}</th> |
| 76 | <th class="text-right">{{ _("Rate") }}</th> |
| 77 | <th class="text-right">{{ _("Amount") }}</th> |
| 78 | </tr> |
| 79 | </thead> |
| 80 | <tbody> |
| 81 | {% for row in doc.items %} |
| 82 | <tr> |
| 83 | <td>{{ row.idx }}</td> |
| 84 | <td>{{ row.item_name }}</td> |
| 85 | <td class="text-right">{{ row.qty }}</td> |
| 86 | <td class="text-right">{{ row.get_formatted("rate", doc) }}</td> |
| 87 | <td class="text-right">{{ row.get_formatted("amount", doc) }}</td> |
| 88 | </tr> |
| 89 | {% endfor %} |
| 90 | </tbody> |
| 91 | </table> |
| 92 | |
| 93 | {% for tax in doc.taxes %} |
| 94 | <p class="text-right">{{ tax.description }}: {{ tax.get_formatted("tax_amount", doc) }}</p> |
| 95 | {% endfor %} |
| 96 | |
| 97 | <p class="text-right"> |
| 98 | <strong>{{ _("Grand Total") }}: {{ doc.get_formatted("grand_total") }}</strong> |
| 99 | </p> |
| 100 | |
| 101 | {% if doc.terms %} |
| 102 | <div style="margin-top: 30px; border-top: 1px solid #ddd; padding-top: 10px;"> |
| 103 | <strong>{{ _("Terms and Conditions") }}</strong> |
| 104 | {{ doc.terms | safe }} |
| 105 | </div> |
| 106 | {% endif %} |
| 107 | ``` |
| 108 | |
| 109 | ### Step 3: Test |
| 110 | |
| 111 | 1. Open a Sales Invoice |
| 112 | 2. Menu > Print > Select "My Invoice Format" |
| 113 | 3. Verify layout and formatting |
| 114 | 4. **ALWAYS** test PDF download — wkhtmltopdf renders differently from browser |
| 115 | |
| 116 | ### Critical Rules for Print Formats |
| 117 | |
| 118 | - **ALWAYS** use `doc.get_formatted("field")` for currency, dates, numbers |
| 119 | - **ALWAYS** pass parent doc for child rows: `row.get_formatted("rate", doc)` |
| 120 | - **ALWAYS** wrap user-facing text with `_("text")` for translation |
| 121 | - **ALWAYS** put CSS in a `<style>` block at the top (not external files) |
| 122 | - **NEVER** use flexbox in v14/v15 (wkhtmltopdf does not support it) — V16 Chrome PDF does |
| 123 | - **NEVER** use `| safe` on user-supplied input — only on trusted system HTML |
| 124 | |
| 125 | --- |
| 126 | |
| 127 | ## Workflow 2: Create an Email Template |
| 128 | |
| 129 | ### Step 1: Create via UI |
| 130 | |
| 131 | ``` |
| 132 | Setup > Email > Email Template > New |
| 133 | - Name: Payment Reminder |
| 134 | - Subject: Invoice {{ doc.name }} - Payment Reminder |
| 135 | - DocType: Sales Invoice |
| 136 | ``` |
| 137 | |
| 138 | ### Step 2: Write Email Content |
| 139 | |
| 140 | **ALWAYS** use inline styles for emails — most clients strip `<style>` blocks. |
| 141 | |
| 142 | ```jinja |
| 143 | <div style="font-family: Arial, sans-serif; max-width: 600px;"> |
| 144 | <p>{{ _("Dear") }} {{ doc.customer_name }},</p> |
| 145 | |
| 146 | <p>{{ _("Invoice") }} <strong>{{ doc.name }}</strong> |
| 147 | {{ _("for") }} {{ doc.get_formatted("grand_total") }} |
| 148 | {{ _("is due for p |