gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 08:21:18 26 4
gpt4 key购买 nike

我试图显示在任务中进行更改的日期。为此,我需要继承小部件“mail_thread”的模板。该模板的定义中没有 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>

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

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

最佳答案

客户端模板(Web 模板,定义在 <templates> 标签内,加载时在客户端用 javascript“编译”)和服务器端模板(通常是 View ,必须包含在__openerp__.py 文件,在启动/升级 odoo 服务器时“编译”)。

您可以使用 <t t-extend="template_name"> 扩展 web/widget 模板模板。后跟一个或多个<t t-jquery="jquery_selector" t-operation="operation">它的行为有点像 xpath,但客户端更“强大”。
您不需要 id,继承是基于模板名称的。 (t-name 指令)

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

    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

    关于templates - 如何在Odoo中继承没有ID的模板?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27907963/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com