I am trying to show the date a change was made in a task. To do this, I need to inherit the template of the widget "mail_thread". That template hasn't an id in its definition. This is it:
<?xml version="1.0" encoding="UTF-8"?>
<template>
<!--
mail.Widget template used to namespace the css -->
<t t-name="mail.Root">
<div class="oe_mail">
</div>
</t>
...
<span t-att-title="widget.date">
<t t-if="widget.timerelative" t-esc="widget.timerelative"/>
<t t-if="!widget.timerelative" t-raw="widget.display_date"/>
</span>
...
</template>
In my module, I need to replace the <span>
tag in order to show the date.
So, how to inherit that template and replace the tag?
There are different inheritance mechanism for client side templates (web templates, defined inside a <templates>
tag, "compiled" with javascript in the client when loading it) and server-side templates (usually views, must be included in the data list in the __openerp__.py
file, 'compiled' when launching/upgrading the odoo server).
You extend web/widget templates templates using <t t-extend="template_name">
followed by one or more
<t t-jquery="jquery_selector" t-operation="operation">
which acts kinda like xpath, but client side and more 'powerful'.
You don't need ids, inheritance is based on the template name. (t-name
directive)
Template inheritance is used to alter existing templates in-place, e.g. to add information to templates created by an other modules.
Template inheritance is performed via the t-extend directive which takes the name of the template to alter as parameter.
The alteration is then performed with any number of t-jquery sub-directives:
<t t-extend="base.template"> <t t-jquery="ul" t-operation="append"> <li>new element</li> </t> </t>
The t-jquery directives takes a CSS selector. This selector is used on the extended template to select context nodes to which the specified t-operation is applied:
- append
the node’s body is appended at the end of the context node (after the context node’s last child)- prepend
the node’s body is prepended to the context node (inserted before the context node’s first child)- before
the node’s body is inserted right before the context node- after
the node’s body is inserted right after the context node- inner
the node’s body replaces the context node’s children- replace
the node’s body is used to replace the context node itsel- No operation
if no t-operation is specified, the template body is interpreted as javascript code and executed with the context node as this
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With