我有名为theme_test的基本主题 ,这是模板代码(此模板添加在清单的数据中)。
<template id="product_catg_test" name="Product Category">
<t t-if="categories">
<code for print category>
</t>
</template>
Run Code Online (Sandbox Code Playgroud)
所以我创建了一个名为test_theme_extended的扩展模块,并尝试了两种继承方法来替换t-if条件
<template id="product_catg_test_extended" inherit_id="theme_test.product_catg_test" name="Test">
<xpath expr="//t[@t-if='categories']" position="replace"></xpath>
</template>
Run Code Online (Sandbox Code Playgroud)
第一种方法给了我一个错误
odoo.tools.convert.ParseError:“元素 '' 无法位于父视图中
<t t-extend="theme_test.product_catg_test">
<t t-jquery="t[t-if='categories']" t-operation="replace"/>
</t>
Run Code Online (Sandbox Code Playgroud)
这也行不通。
我认为主视图是从主题创建的,并且没有外部 ID,这就是我面临这个问题的原因。但是如何继承扩展模块中的基本主题视图呢?
小智 5
如果您要继承一个主题,则它必须来自另一个主题,或者使用记录而不是模板。
由于模块主题在主题 ir_ui_view 中创建视图并在 ir_ui_view 中创建没有 XMLID 的副本
普通模块在 ir_ui_view 中创建视图
因此,如果您想从普通模块(ir_ui_view)修改视图主题(theme_ir_ui_view),那么实际上它不会找到该元素,因为它位于另一个表中
但如果你仍然想尝试你可以用这种方式进行继承,继承没有XML的副本,所以你必须通过键进行继承
<record id="product_catg_test_extended" model="ir.ui.view">
<field name="name">product_catg_test_extended</field>
<field name="inherit_id" search="[('key', '=', 'theme_test.product_catg_test')]"/>
<field name="type">qweb</field>
<field name="key">test_theme_extended.product_catg_test_extended</field>
<field name="arch" type="xml">
<xpath expr="//t[@t-if='categories']" position="replace"></xpath>
</field>
</record>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
1511 次 |
最近记录: |