How to Inherit Templates in Odoo QWeb

November 3, 2025 by
How to Inherit Templates in Odoo QWeb
Fazri Muhammad Yazid

Odoo uses a flexible templating engine called QWeb to render HTML views for both frontend and backend interfaces. Whether you’re customizing a website page or modifying how records appear in the backend, understanding how QWeb templates work, especially t-name, t-inherit, and XPath is essential for every Odoo developer.

This guide will walk you through the basic concepts, inheritance methods, and practical examples to help you safely extend existing templates without editing Odoo’s core files.

1. What is QWeb?

QWeb is Odoo’s XML-based templating engine used to generate dynamic HTML content. It allows you to insert logic, variables, and conditions directly within XML tags.

Example of a simple QWeb snippet:

<t t-name="example_hello_world">
    <div>Hello, <t t-out="object.name"/>!</div>
</t>

Here, t-name defines the template identifier, and t-out outputs a field or variable.


2. Understanding t-name

The attribute t-name assigns a unique name to your template.
It works like a reference so that other templates or modules can inherit or call it later.

Example:

<t t-name="my_module.order_confirmation">
    <div>
        <p>Thank you for your order, <t t-out="object.partner_id.name"/>!</p>
    </div>
</t>

When loaded, Odoo stores this template under that t-name, allowing you to extend or call it from another module.


3. Inheriting Qweb with t-inherit

Instead of rewriting an entire template, Odoo lets you extend or modify existing ones using the t-inherit attribute.
This is how you safely customize templates without touching the core code.

Example:

<t t-inherit="original.template.name" t-inherit-mode="extension">
    <xpath expr="//div[@class='some_class']" position="after">
        <p>This is my custom addition.</p>
    </xpath>
</t>

Key attributes:

  • t-inherit → the name of the template you want to modify.
  • t-inherit-mode → defines how inheritance works (usually extension for most cases).
  • xpath → locates the exact element you want to modify or extend.

When you’re defining templates inside your module XML files (e.g., under views/), you typically wrap them with <template> inside <odoo>.
The logic works the same, just with slightly different syntax.

Example:

<template 
​id="website_sale_confirmation_inherit"
​inherit_id="website_sale.confirmation" name="Website Sale Confirmation Inherit">
    <xpath expr="//div[@class='oe_website_sale']/p" position="after">
        <p class="text-info">Track your order anytime in your account dashboard.</p>
    </xpath>
</template>

Key difference:

  • inherit_id is used instead of t-inherit.

4. XPath Position Attributes

Odoo’s QWeb xpath supports a few key positions you’ll use frequently:

Position

Description

Example

before

Inserts your content before the target element.

<xpath expr="//div[@id='footer']" position="before">
after

Inserts your content after the target element.
<xpath expr="//table" position="after">
inside

Adds your content inside the selected tag.

<xpath expr="//div[@class='cart_total']" position="inside">
replace

Completely replaces the selected element with your new content.

<xpath expr="//h1" position="replace">
attributes

Changes or adds attributes of the selected element.

<xpath expr="//a[@id='buy_now']" position="attributes">

5. How expr Works

The expr attribute uses XPath syntax.

Here are some useful examples:

XPath Expression

Meaning

//div[@class='alert']

Selects <div> elements with class “alert”.

//table/tbody/tr[1]

Selects the first <tr> in every <tbody> inside a <table>.

//p[last()]

Selects the last <p> element in the structure.

//div[contains(@class, 'summary')]
Selects <div> elements whose class contains “summary”.


How to Inherit Templates in Odoo QWeb
Fazri Muhammad Yazid November 3, 2025
Share this post
Archive