1

I tried to use QWeb Template in a custom view. I don't find any documentation explaining this, any reference?

Here's the sample code:

<record id="realestate_property_view_form" model="ir.ui.view">
    <field name="name">realestate.property.form</field>
    <field name="model">realestate.property</field>
    <field name="arch" type="xml">
        <form string="Property">
            <header>
                <button name="approve_action" type="object" string="Approve"/>
            </header>
            <sheet>
                <group>
                    <group>
                        <field name="name" />
                        <field name="address" />
                    </group>
                    <template>
                        <t t-name="templatePreviewBox">
                            <div>
                                <img t-attf-src="'http://localhost:3000/rest/api/' + record.image_url.raw_value" />
                            </div>
                        </t>
                    </template>
                </group>
            </sheet>
        </form>
    </field>
</record>

The problem is that if I inspect element in the browser, it's still displayed as <img t-attf-src> instead of <img src>, and the string expression seems not evaluated.

I find the documentation in Odoo official site is not complete enough, so I really appreciate for any references or documentation about this QWeb.

Yosi Pramajaya
  • 3,895
  • 2
  • 12
  • 34

1 Answers1

1

You can read in the official documentation that form views are composed of regular HTML with additional structural and semantic components and the template element is not one of them.

In HTML, the template element is used to declare fragments of HTML that can be cloned and inserted in the document by script. In a rendering, the template element represents nothing.

To understand how QWEB templates are rendered, refer to QWeb Template Engine and QWeb Templates.

Kenly
  • 24,317
  • 7
  • 44
  • 60