Thursday, 1 June 2017

Odoo: Set/use context in email templates

Today we are going to discuss, how to use/change context in dynamic/custom templates.

Let's say we want to send some values to email template other than normal object id, here is the code for that

In controllers/main.py

local_context = request.env.context.copy()

in module.py file

local_context = self.env.context.copy()
local_context.update({
    'name': 'Shiv',
    'place': 'Bangalore'
})

template = request.env.ref('module_name.email_template_id')
            template.with_context(local_context).send_mail(object.id, force_send=True, raise_exception=True)

In email template code you can access context as:

<p>${ctx['name']}</p>
<p>${ctx['place']}</p>

That's it.

Thanks!!! Enjoy Programming!!! :)

To know how to create custom email template, please check here: http://www.odoo.yenthevg.com/creating-mail-templates/


No comments:

Post a Comment

Thanks for your valuable comments.

Gmail: Download blocked file

Hi, today we are going to learn, how to download blocked file in gmail. Sometimes you see following message in gmail: and you can...