ERPNext Foundation ERPNext Cloud User Manual Blog Discuss Frappé* Donate

How test is string is empty in jinja template for document

jinja

#1

Hello,

I createda custom template for quotation. Each item in the quotation can or cannot have a description.

If description is defined, it should be shown. If no description is defined, it should not display anything.

The problem is that if no description is defined, a blank line is displayed.

I tried a lot of things. The last attempt was:

		<td style="width: 48%;">
                        <small>
                            {{ row.item_name }}
                            {% if row.description != '' -%}
                                This is a test
                                [{{ row.description }}]
                            {%- endif %}
                        </small>
                    </td>

It did not work. How can I do it?

I am printing “This is a test” text only to check if the “if” statement works or not.

when seen page source, I see that “description” property has the value of

<div><br></div>

Is there a way to clean that HTML?

Thanks
Jaime


#3

html2text function is accessible from Jinja templates in Frappe.

You can use it like so:

html2text("<div><br><div>").strip()  # outputs empty string

Edit: You can also try the striptags filter available in Jinja.


#4