我想为odoo创建一个新主题。我通过创建一个新模块并安装它来完成它。我在本文档here中看到,odoo通过使用t-extend关键字来支持模板继承。但是,我无法做到。 这是我的自定义模板:
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="website.homepage" name="Homepage" page="True">
<div class="header">
<h1>FOO<h1>
<div class="main">
</div>
</div>
</template>
<template id="website.contact" name="Homepage" page="True">
<t t-extend="website.homepage">
<t t-jquery="div.main" t-operation="inner">
<h1>FOO 2</h1>
</t>
</t>
</template>
</data>
</openerp>
模板website.contact应该显示FOO和FOO 2,但它只显示了FOO 2。 请帮我解释一下。感谢。
答案 0 :(得分:10)
您使用客户端模板的语法,但这些是服务器端模板。您可以将继承与服务器端模板一起使用:
<template id="contact" inherit_id="website.homepage">
<xpath expr="//div[@class='main']" position="inside">
<h1>FOO 2</h1>
</xpath>
</template>
您可以阅读更多in the official documentation。
答案 1 :(得分:1)
您正在尝试创建新主题。你在使用odoo 8.0吗?我问这个是因为您发布的链接是针对OpenERP 7.0的 因此,对于Odoo 8.0,可以看到here的新文档,QWEB可以在QWEB找到它。
现在主要的是,如果您尝试为CMS或网站模块创建新主题,那么您必须完成这些steps。
答案 2 :(得分:0)
在父模板中,添加<t t-raw="0"/>
或<t t-raw="name"/>
,模板:...代码html ...
答案 3 :(得分:0)
在此处使用Xpath,您可以继承并更改父级tempaltes,示例如下。
/example
或尝试
<input>
您也可以通过覆盖该模板来尝试这些:
/example
在覆盖时,不要忘记给出确切的ID,后跟模块名称。 干杯!
答案 4 :(得分:0)
你好Minh-Hung Nguyen,
试试这段代码,
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="website.homepage" name="Homepage" page="True">
<div class="header">
<h1>FOO<h1>
<div class="main">
</div>
</div>
</template>
<template id="website.contact" name="Homepage" page="True">
<t t-extend="website.homepage">
<!-- Use 'append' to add the h1 tag inside main div -->
<t t-jquery="main" t-operation="append">
<h1>FOO 2</h1>
</t>
</t>
</template>
</data>
</openerp>
我希望我的回答对您有所帮助。