Frappe edit custom html dialog modifies jinja template

I want to render table in custom print format.

Template is taken from example (https://frappe.github.io/erpnext/user/manual/en/customize-erpnext/print-format.html)

<table class="table table-bordered">
        <tbody>
            <tr>
                <th>Sr</th>
                <th>Item Name</th>
                <th>Description</th>
                <th class="text-right">Qty</th>
                <th class="text-right">Rate</th>
                <th class="text-right">Amount</th>
            </tr>
            {%- for row in doc.items -%}
            <tr>
                <td style="width: 3%;">{{ row.idx }}</td>
                <td style="width: 20%;">
                    {{ row.item</em>name }}
                    {% if row.item<em>code != row.item</em>name -%}
                    <br>Item Code: {{ row.item<em>code}}
                    {%- endif %}
                </td>
                <td style="width: 37%;">
                    <div style="border: 0px;">{{ row.description }}</div></td>
                <td style="width: 10%; text-align: right;">{{ row.qty }} {{ row.uom or row.stock</em>uom }}</td>
                <td style="width: 15%; text-align: right;">{{
                    row.get<em>formatted("rate", doc) }}</td>
                <td style="width: 15%; text-align: right;">{{
                    row.get</em>formatted("amount", doc) }}</td>
            </tr>
            {%- endfor -%}
        </tbody>
    </table>

After saving custom HTML template is modified to:

  {%- for row in doc.items -%}
    
    {%- endfor -%}
<table class="table table-bordered">
<tbody>
    <tr>
        <th>Sr</th>
        <th>Item Name</th>
        <th>Description</th>
        <th class="text-right">Qty</th>
        <th class="text-right">Rate</th>
        <th class="text-right">Amount</th>
    </tr><tr>
        <td style="width: 3%;">{{ row.idx }}</td>
        <td style="width: 20%;">
            {{ row.itemname }}
            {% if row.item<em>code != row.item</em>name -%}
            <br>Item Code: {{ row.item<em>code}}
            {%- endif %}
        </em></td>
        <td style="width: 37%;">
            <div style="border: 0px;">{{ row.description }}</div></td>
        <td style="width: 10%; text-align: right;">{{ row.qty }} {{ row.uom or row.stockuom }}</td>
        <td style="width: 15%; text-align: right;">{{
            row.get<em>formatted("rate", doc) }}</em></td>
        <td style="width: 15%; text-align: right;">{{
            row.getformatted("amount", doc) }}</td>
    </tr></tbody>

Loop position now is before table. From debugging - it is made by java script. Any ideas how to fix this or write needed template?

Hi @yrunts,

please replace all the <em> and </em> tag with _ and try again.

Thanks,
Makarand

Dear Makarand, the problem is not in em tag. Template text is modified after pressing Update button in Edit Custom HTML dialog.

Input:

<table>
    <tbody>
        <tr>
            <th>Sr</th>
        </tr>
        {%- for row in doc.items -%}
            <tr>
                <td>{{ row.idx }}</td>
            </tr>
        {%- endfor -%}
    </tbody>
</table>

Result:

        {%- for row in doc.items -%}
            
        {%- endfor -%}
    <table class="table table-bordered">
    <tbody>
        <tr>
            <th>Sr</th>
        </tr><tr>
                <td>{{ row.idx }}</td>
            </tr></tbody>
</table>

I’m seeing the same problem as above, was this ever resolved?

The Jinja {%- for row in doc.items -%} and {%- endfor -%} are moved out of the Table when Custom HTML is saved in Print Format Builder.

No,

My workaround is saving print template directly to db.

update tabPrint Format set format_data = ‘’ where name = ‘format name’

Thanks for that, I’ll give it a go. Much appreciated.

I ran into this today. I created the following issue.

https://github.com/frappe/frappe/issues/2229