Odoo Template Extend in Custom Module

Template Extend - Inheritance Odoo

Probuse Admin
Odoo Tips by Probuse Consluting Service Pvt Ltd

A Great Headline

A good subtitle

 

Concept of template inheritance:

How to inherit template

Main Template:

<t t-name="UserMenu">
    <span class="my_account">My Account</span>
</t>

Menu have options: ['My Account']

Extend:
    <t t-extend="UserMenu">
</t>

Operations:

* Append (it will place new element after selected element)
    <t t-extend="UserMenu">
        <t t-jquery="span.my_account" t-operation="append">
            <span class="logout">Logout</span>
        </t>
    </t>

Menu have options: ['My Account', 'Logout']

* Prepend (it will place new element before selected element)
    <t t-extend="UserMenu">
         <t t-jquery="span.my_account" t-operation="prepend">
             <span class="preference">Preference</span>
         </t>
    </t>

Menu have options: ['Preference', 'My Account']

* Replace (it will replace element with new element)
    <t t-extend="UserMenu">
         <t t-jquery="span.my_account" t-operation="replace">
              <span class="my_account_new">My Account New</span>
          </t>
      </t>

Menu have options: ['My Account New']

* Add element attributes (we can add attributes using js)

<div t-extend="UserMenu">
        <t t-jquery="span.my_account">
            this.attr('t-if', 'widget.session.is_admin');
        </t>
    </div>
- It will add t-if attribute on My Account span.