How can I make a Python function accessible in Qweb templates.
Like the Python function slug()
being used in templates in website_sale and website_hr_recruitment modules
0
votes
1 Answers
2
votes
For qweb reports, define the function in the model. For example, you have inherited the model account.invoice
and you want to add something in the qweb report template, you create a function like:
@api.multi
def myfunction(self, s):
return s.lower()
Then in your template, you can call it like <span t-esc="o.myfunction('Hello')"/>
.
In a website template, you can include the function in the render context like:
http.request.website.render(
"my_module.my_template",
{'myfunction': self.myfunction})
Then you can call it as usual: <span t-esc="myfunction('Hello')"/>