如何在Odoo中继承没有ID的模板? [英] How to inherit a template with no ID in Odoo?

查看:83
本文介绍了如何在Odoo中继承没有ID的模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图显示在任务中进行更改的日期.为此,我需要继承小部件"mail_thread"的模板.该模板的定义中没有ID.就是这样:

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>

在我的模块中,我需要替换<span>标记以显示日期.

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?

推荐答案

客户端模板有不同的继承机制(Web模板,在<templates>标记内定义,在加载时与客户端中的javascript编译"在一起)和服务器端模板(通常,视图必须包含在__openerp__.py文件的数据列表中,在启动/升级odoo服务器时会被编译").

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).

您先使用<t t-extend="template_name">扩展Web/小部件模板模板,然后再扩展一个或多个 <t t-jquery="jquery_selector" t-operation="operation">的行为有点类似于xpath,但是客户端方面更强大".
您不需要ID,继承基于模板名称. (t-name指令)

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)

  • Server-Side view inheritance
  • Client-Side template inheritance:

模板继承用于就地更改现有模板, 例如将信息添加到其他模块创建的模板中.

Template inheritance is used to alter existing templates in-place, e.g. to add information to templates created by an other modules.

模板继承通过t-extend指令执行,该指令 以要更改的模板名称作为参数.

Template inheritance is performed via the t-extend directive which takes the name of the template to alter as parameter.

然后使用任意数量的t-jquery执行更改 子指令:

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>

<t t-extend="base.template"> <t t-jquery="ul" t-operation="append"> <li>new element</li> </t> </t>

t-jquery指令采用CSS选择器.该选择器用于 扩展模板,用于选择指定了上下文的节点 进行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:

  • 附加
    节点的主体附加在上下文节点的末尾(在上下文节点的最后一个子节点之后)
  • 前置
    节点的主体位于上下文节点之前(在上下文节点的第一个子节点之前插入)
  • 之前
    该节点的主体被插入到上下文节点之前
  • 之后
    该节点的主体被插入到上下文节点之后
  • 内部
    节点的主体替换了上下文节点的子节点
  • 替换
    该节点的主体用于替换上下文节点itsel
  • 无操作
    如果未指定t运算,则模板主体将解释为javascript代码,并使用上下文节点以此形式执行
  • 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

这篇关于如何在Odoo中继承没有ID的模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆