Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Templates 如何在Odoo中继承没有ID的模板?_Templates_Odoo - Fatal编程技术网

Templates 如何在Odoo中继承没有ID的模板?

Templates 如何在Odoo中继承没有ID的模板?,templates,odoo,Templates,Odoo,我试图显示任务中进行更改的日期。为此,我需要继承小部件“邮件线程”的模板。该模板的定义中没有id。就是这样: <?xml version="1.0" encoding="UTF-8"?> <template> <!-- mail.Widget template used to namespace the css --> <t t-name="mail.Root"> <div class="oe

我试图显示任务中进行更改的日期。为此,我需要继承小部件“邮件线程”的模板。该模板的定义中没有id。就是这样:

<?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>

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


那么,如何继承该模板并替换标记呢?

对于客户端模板(web模板,在
标记中定义,“加载时在客户端使用javascript编译”)和服务器端模板,有不同的继承机制(通常情况下,视图必须包含在启动/升级odoo服务器时“已编译”的
\uuu openerp\uuuu.py
文件的数据列表中)

您可以使用
后跟一个或多个扩展web/widget模板
它的行为有点像xpath,但客户端更强大。
您不需要ID,继承基于模板名称。(
t-name
directive)

模板继承用于就地更改现有模板, e、 g.向其他模块创建的模板添加信息

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

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


  • 新元素
  • t-jquery指令采用CSS选择器。此选择器用于 用于选择指定上下文的上下文节点的扩展模板 t型操作适用于:

    • 追加
      节点的主体附加在上下文节点的末尾(在上下文节点的最后一个子节点之后)
    • 预结束
      节点的主体在上下文节点之前(插入到上下文节点的第一个子节点之前)

    • 节点的主体插入到上下文节点的正前方

    • 节点的主体插入到上下文节点的正后方
    • 内部
      节点的主体将替换上下文节点的子节点
    • 替换
      节点的主体用于替换上下文节点itsel
    • 无操作
      如果未指定t操作,则模板主体将被解释为javascript代码,并与上下文节点一起执行,如下所示

    我还想更改这个xml文件中的日期显示格式,所以我将这个默认布局的整个模板复制到了我的新模块中,只更改了span标记中的日期

    <?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>
    
    
    ....
    ....
    
    需要在中声明此xml文件

    这对我有用