Alpha Geek
Alpha Geek

Reputation: 489

Odoo Email template not rendering

I am trying to create a email template and trying to add some conditions

%if object.origin:
origin : ${object.origin or ''}
%endif 

but when I am trying to render the template it is only rendering the $part not the %if %endif part,

so the %if and %end if looks visible in the email template, and it is not performing the conditions.

how to overcome?

Upvotes: 0

Views: 1319

Answers (2)

Jorge Solano Kirk
Jorge Solano Kirk

Reputation: 1

sharing knowledge:

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.

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

credits to Oliver Dony (more details)

Upvotes: 0

Atul Arvind
Atul Arvind

Reputation: 16743

Odoo uses jinja & mako template engine for the email template, your code looks like you have used mako template, but you can try out jinja templates. After you apply the jinja template the code become different like,

{% if object.origin %}
origin : ${object.origin or ''}
{% endif %}

Upvotes: 1

Related Questions