Odoo Help

8 Answers

Olivier Dony (odo)

--Olivier Dony (odo)--

| 7 6 8
Ramilies, Belgium
--Olivier Dony (odo)--


Olivier Dony (odo)
1/28/15, 11:26 AM

When a non-empty [email] template is rendered blank, it means the rendering engine failed to parse the template.

This parsing problem is likely caused by a combination of factors:

  • The `%` syntax in Jinja2/Mako templates corresponds to line statements, and this only works as soon as the % sign is the first non-blank character on the line.
  • When you're dealing with HTML templates (as is the case for email templates), there's a very very good chance every line has a lot of invisible HTML tags before the % sign, or that the % sign is not on its own line.

To convince yourself, switch to the source view of your template (the rightmost icon in the HTML editor toolbar, looking like `[<>]`), and you'll see the mixup.

This is why it works when you change the templates in the XML source files of Odoo directly, as you're dealing with the raw HTML source in that case.

Solution: use the source view to write HTML directly, where you can use the full Jinja2 syntax including line statements. Some advanced users might also want to permanently switch to a plaintext version of the template body, by editing the form view of mail templates and forcing `widget="text"` for the `body_html` field. This is safer if you do advanced things, because the HTML editor could also reject/mess up templates that do not contain valid HTML, for example with % line statements in between `<tr>` or `<td>` elements in a table.
You could also try to use the ```` markers for block statements, but that will definitely fail with the HTML editor (even in source mode) because the angle brackets will be auto-escaped, being invalid HTML tags.

One more possible issue: watch out that you cannot use variables expressions on the line statement itself,  another common mistake that seems present in the issue description... 

This is invalid:
  % if object.street2: ${(object.street or '-') | safe}
  % endif

While this is valid (even if quite strange, mixing 2 different fields):
  % if object.street2:
      ${(object.street or '-') | safe}
  % endif

If you're not sure, check the Jinja2 documentation.


4/4/16, 3:12 AM

We are having a similar issue in Odoo v9. Modifying the templates without being aware of the tag requirements can result in this error. However, editing the mail template again and using the 'code' view in the content editor to reinstate the default system template did not fix it. We compared this template to a fresh install and there was no difference.

In the end, the only thing that worked was finding the corresponding entry in the PostgreSQL database and reverting that back to the system default. Suddenly it works fine.

It certainly seems from here that the Odoo editor features for mail templates will break the formatting no matter how you submit them (wysiwyg or code view). I think it should be considered a bug.

Victor Efimov
3/19/18, 5:54 PM

Oh, through years I've stumbled on this issue again. Thank for sharing this remedy!

Luis Triana
2/23/17, 2:41 PM

There is an issue there the %if &endif is not working, i don't know why, the way i solved was this:

I did it in the mail template for sale.order:

     Order reference: ${(object.origin or 'No Origin Document'}

Hope this works in your mail template.

Jonas Hoekman
4/21/16, 5:06 PM

I have almost the same problem the template is just not fully parsed, I have edited the default invoice and sales order templates and need to be able to restore these back to the original ones, on a development server I was able to do this by removing the templates and update the module account_voucher, but on my production server I have always 504 Gateway Time-out (nginx)

have tried another way by exporting these both the templates and the Dutch (BE)/ Nederlands (BE) translations on a new server installation and import it on the production server but seems not to work. 

Lithin T
1/28/15, 3:02 AM

It should work if the fields are specifed are in the object you selected.
see the below sample applied to sale.order object which %if %endif works perfect.

  Order number: ${object.name}

  Order total: ${object.amount_total} ${object.pricelist_id.currency_id.name}

  Order date: ${object.date_order}
% if object.origin:   Order reference: ${object.origin}
% endif % if object.client_order_ref:   Your reference: ${object.client_order_ref}
% endif % if object.user_id:   Your contact: ${object.user_id.name} % endif 


Yenthe Van Ginneken
1/28/15, 3:06 AM

Thanks for your answer Lithin. Did you create a new template for mass mailing and through the webinterface though? This shouldn't work as it is even confirmed by the Odoo developers. This question was made to intentionally be answered by one of the Odoo developers & to promote it to the docs, as you can see in this Github report which explains everything: https://github.com/odoo/odoo/issues/4671

Lithin T
1/28/15, 3:39 AM

Yes Yenthe,I confirmed. through webinterface it is not working fine as expected.

Ask a Question
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now