Vaidation error in Custom Print Format for Sales Invoice for use in POS

Is it possible to use for loop as below in a Custom Print Format.

{% for item in items %}
{% for(var i=0; i<item.qty; i++) %}
{{ item.item_name }}
{% { %}
{% endfor %}

The above html does not validate when creating a Custom Print Format. Print Format Type is JS. This construct is used in several html templates else where in erpnext.

It seems that this uses the Simple John Resig templating while rendering, but the validation in the Print Format for is for Jinja template.

Custom Print Formats are in Jinja!

JS Templating is only for custom print formats for reports.

Works perfectly. Thanks.

{%- for item in doc.items -%}
	{%- for i in range(item.qty) -%}
	<p class="text-center">
		{{ }}<br>
		{{ doc.select_print_heading or _("Invoice") }}<br>
		<b>{{ _("Receipt No") }}:</b> {{ }}<br>
		<b>{{ _("Date") }}:</b> {{ doc.get_formatted("posting_date") }}<br>
		<b>{{ _("Customer") }}:</b> {{ doc.customer_name }}

	{%- endfor -%}
{%- endfor -%}
1 Like

The above html works when printing from the Sales Invoice form. But not when printing from Pos.

Workaround : Used {% raw %} {% endraw %} in html and modified \apps\frappe\frappe\public\js\lib\microtemplate.js to skip Jinja raw tag

// {% raw %} --> 
str = str.replace(/{%\s?raw\s?%}/g, "");

// {% endraw %} --> 
str = str.replace(/{%\s?endraw\s?%}/g, "");
1 Like