0

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

1 Answer 1

2

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')"/>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.