Print Preview Error only shows {{ body }} when nested for loop is used

Hi everyone,

I am facing a problem with the custom print format using nested loop for.

The goal for this custom print format is to print item labels for each item in Sales Order according to the quantity. Here is code:

{% for row in doc.items %}
	{% for i in range(row.qty) %}
	<table width="100%">
	<tbody>
	<tr>
		<td class="kh1"> 
			{{ row.idx }}
		</td>
	</tr>
	<tr>
		<td class="kh1" style="font-family: Khmer OS Bokor;"> 
			{{ doc.customer }}
		</td>
	</tr>
	<tr>
		<td class="kh1 text-right" style="font-family: Khmer OS;">
			{{ row.description }}
		</td>
	</tr>
	</tbody>
	</table>
 		<div class="page-break"></div>
	{%- endfor -%}
{%- endfor -%}

But when I use only one for loop, the Print Preview works fine

{% for row in doc.items %}
	<table width="100%">
	<tbody>
	<tr>
		<td class="kh1"> 
			{{ row.idx }}
		</td>
	</tr>
	<tr>
		<td class="kh1" style="font-family: Khmer OS Bokor;"> 
			{{ doc.customer }}
		</td>
	</tr>
	<tr>
		<td class="kh1 text-right" style="font-family: Khmer OS;">
			{{ row.description }}
		</td>
	</tr>
	</tbody>
	</table>
 		<div class="page-break"></div>

{%- endfor -%}

Any idea what is wrong with my code?

Hello, @Ratanak

You need to typecast it into int from string
((row.qty) |round|int )

Thank you very much. This works perfectly.

hey Rohan,

wow, this is a difficult error to catch just by looking at the code; question: is there any way to ‘compile’ or take the code to any tool to see the syntax error?

Hey @alexsilva, I do not know if there is any way to compile the code or to see the error.
I just taught the error by looking at the code because I also got the same error when I was doing a custom print format.