Reputation: 173
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?
Upvotes: 6
Views: 7207
Reputation: 361
I also wanted to change the date show format in this xml file. So I copied the whole template for this default layout to my new module and only changed date in the span tag.
<?xml version="1.0" encoding="UTF-8"?>
<template>
<!-- default layout -->
<t t-name="mail.thread.message">
....
<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"/>-->
<t t-raw="widget.display_date"/>
</span>
....
</t>
</template>
need to declare this xml file in your __openerp__.py
It worked for me.
Upvotes: 0
Reputation: 2896
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
Upvotes: 11