After spending a day digging around in the source code, I found a solution! This is actually not related to the template, but I got the idea from the source text widget source code by default, so I think that this should not be considered as a “hack”.
Here is my custom widget class:
openerp.mymodule = function(instance, local) { instance.ImageDisplayer = instance.web.form.AbstractField.extend({ template: "ImageDisplayer", init: function (view, code) { this._super(view, code); },
My template now contains nothing special:
<?xml version="1.0" encoding="UTF-8"?> <templates xml:space="preserve"> <t t-name="ImageDisplayer"> <img /> </t> </templates>
It works like a charm. It even refreshes the page whenever I make changes on the server side.
The Odoo documentation really needs to be more talkative.
Update: The answer applies to Odoo 8. It may work slightly differently in Odoo 9 because they redefined the user interface structure in the new version.
source share