【问题标题】:Template inheritance in odoo 13/14odoo 中的模板继承 13/14
【发布时间】:2021-01-12 06:01:21
【问题描述】:

我一直在努力做到这一点。我有一个包含一堆 css 和 js 文件的模板。我想扩展模板并添加一个文件。

模板1

<template id="template1_assets_frontend" name="SP Registration Full Form Assets Frontend" >     
    <script type="text/javascript" src="/test/static/src/js/test1.js" />
</template>

现在我想创建扩展 template1 并添加一个 js 文件的 template2。 我已经像这样使用inherit_id

<template id="template2_assets_frontend" name="SP Registration Full Form Assets Frontend" inherit_id="template1">
    <xpath expr="//script[last()]" position="after">
        <script type="text/javascript" src="/test/static/src/js/test2.js" />
    </xpath>
</template> 

但问题是,它也在修改 template1。我不想那样。

【问题讨论】:

    标签: xml templates inheritance odoo qweb


    【解决方案1】:

    在这上面花了 1-2 小时后,我才知道有一个属性 primary="True" 来实现这一点,它隐藏在这里:https://www.odoo.com/documentation/14.0/reference/data.html#template

    所以扩展的模板会是这样的:

    <template id="template2_assets_frontend" name="SP Registration Full Form Assets Frontend" inherit_id="template1" primary="True">
        <xpath expr="//script[last()]" position="after">
            <script type="text/javascript" src="/test/static/src/js/test2.js" />
        </xpath>
    </template> ```
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-04-28
      • 1970-01-01
      • 2018-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-23
      相关资源
      最近更新 更多