How to include view in Odoo 8

纵饮孤独 提交于 2019-12-13 17:53:14

问题


As in the title. How do you include a view file from a view file?

If you have a large xml view file with thousand lines would it be great if you can split them into partial view then include them in the main view.

I have experimented with t t-call but it doesn't work

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

回答1:


t-call Attribute :

Which is works only in Qweb template but we can not call with the Odoo generic view like tree view, form view, search view and many more. but we can only inherit the existing view with inherit_id Attribute in new inherited custom view.

For Example

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

Actually Usage of t-call Attribute: Calling sub-templates

QWeb templates can be used for top-level rendering, but they can also be used from within another template (to avoid duplication or give names to parts of templates) using the t-call directive:

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

This calls the named template with the execution context of the parent, if other_template is defined as:

   <template id="new-template">
    <t t-call="other-template">
      <em>content</em>
     </t>
   </template>

Result :

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

This is possible only with Qweb template view.

I hope my answer may help you



来源:https://stackoverflow.com/questions/45973115/how-to-include-view-in-odoo-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!