如何在 Odoo 8 中包含视图

How to include view in Odoo 8

如题。如何从视图文件中包含视图文件?

如果您有一个包含数千行的大型 xml 视图文件,如果您可以将它们拆分为部分视图然后将它们包含在主视图中,那就太好了。

我已经尝试过 t t-call 但它不起作用

<notebook>
    <page string="Page 1">
        <t t-call="module.page_1"/>
    </page>
    <page string="Page 2">
        <t t-call="module.page_2"/>
    </page>
</notebook>

t-call 属性:

这仅适用于 Qweb 模板,但我们不能使用 Odoo 通用视图(如树视图、表单视图、搜索视图等)调用。 但我们只能在新继承的自定义视图inherit_id属性中继承现有视图。

例如

<field name="inherit_id"ref="product.product_template_only_form_view"/>

t-call属性的实际使用:调用子模板

QWeb 模板可用于顶层渲染,但也可使用 t-call 指令在另一个模板中使用它们(以避免重复或为部分模板命名):

<template id="other-template">
   <div>
     This template was called with content:
  </div>
<template>

如果 other_template 定义为:

,这将使用父级的执行上下文调用命名模板
   <template id="new-template">
    <t t-call="other-template">
      <em>content</em>
     </t>
   </template>

结果:

<div>
    This template was called with content:
    <em>content</em>
</div>

这仅适用于 Qweb 模板视图。

希望我的回答对您有所帮助