Community mailing list archives

Re: Render a html field as qweb

Yannik Lieblinger
- 01/23/2016 16:01:29

Hi Paul,

Hi all,

sorry, I've made an failure. The get_text() function only returns false.

    def get_text(self):
        # For testing
        env = api.Environment(, self.uid, self.localcontext)
        template = env['clb_presuffix_text.config'].search([('textType', '=', 'pretext')]).text
        user = env['res.users'].browse(env.uid)
        # try to load the template
        model = env['sale.order']
        ids = env['res.partner'].search([('id', '=', 379)])
        mail = env['email.template']
            template = mako_template_env.from_string(tools.ustr(template))
        except Exception:
            _logger.exception("Failed to load template %r", template)
            return results
        variables = {
            'user': user,
            'ctx': env['res.partner'].search([('id', '=', 379)]),
            'testVar': 'Test text. Is not shown : (.',
            render_result = template.render(variables)
        except Exception:
            _logger.exception("Failed to render template %r using values %r" % (template, variables))
            render_result = u""

        return render_result

I will take an deeper look into the mail template module, maybe I find an solution to fix it.

But I would be really thankful if somone had an idea or an helpful tip.

Thanks for all!

Regards Yannik

Paul Catinean <> hat am 22. Januar 2016 um 13:12 geschrieben:

Hello Yannik,

Glad to have you among us

I'm not sure if this is the best way to do it but it works for emails that need parsing variables and translation before sending

Using QWeb alone should be possible too but for messages like you mentioned I think the mako syntax is much easier

1. Firstly import the mako template environment and openerp tools

from openerp.addons.email_template.email_template import mako_template_env
from openerp import tools

2. Then you use the mako template environment to render and translate your content using mako syntax:


You can place the final result in a variable or a method and call from qweb using t-esc (which is safer and does not need to do anything except output the result)

You can also find examples of mako templates in the standard Email templates

Hope this helps


On Fri, Jan 22, 2016 at 11:36 AM, Yannik Lieblinger <> wrote:

Hi all,

I try to build an new module for our sales order and invoice reports.

The Module should add custom text with variables like to the end of the report. I have create an Class with an text field which should hold the custom qweb subtemplates.

If I call the field via t-raw all looks great but no variables getting rendered and they are printed as text only. I'm new to odoo, so I don't really understand the python print workflow. But is there a possibility to render my templates from the text field with variables which are available in the sale order document?

Regards Yannik


Post to:

Post to: