我正在开发一个使用Odoo v8的网站。我想写一个代码片段,它的结构是通过javascript加载的。贝娄是我的代码...... 首先,我有一个片段结构:
<template id="snippet_hello" inherit_id="website2.snippets" name="Snippet Hello">
<xpath expr="//div[@id='snippet_structure']" position="inside">
<div class="oe_snippet">
<div class="oe_snippet_thumbnail">
<img class="oe_snippet_thumbnail_img" src="/path_to_block_icon/block_icon.png"/>
<span class="oe_snippet_thumbnail_title">Hello</span>
</div>
<section class="oe_snippet_body">
<div class="oe_snippet_hello">Hello ...</div>
</section>
</div>
</xpath>
<xpath expr="//div[@id='snippet_options']" position="inside">
<div data-snippet-option-id='snippet_hello'
data-selector=".oe_snippet_hello"
data-selector-siblings="p, h1, h2, h3, blockquote, .well, .panel">
</div>
</xpath>
</template>
然后我有一些javascript代码来呈现代码段内容:
(function () {
'use strict';
var website = openerp.website;
qweb = openerp.qweb;
qweb.add_template('/path_to_snippet_qweb_template/snippet_template_filename.xml');
website.snippet.animationRegistry.hello = website.snippet.Animation.extend({
selector: ".oe_snippet_hello",
start: function(){
var $content = $(qweb.render('website.snippet_hello', {a:1}));
$content.appendTo(this.$target);
},
});
})();
然后我有一个QWeb模板来显示我的结构内容(filename:snippet_template_filename.xml):
<?xml version="1.0" encoding="utf-8"?>
<templates id="template" xml:space="preserve">
<t t-name="website.snippet_hello">
<div contenteditable="false">
<p>Hello snippet</p>
<t t-esc="a"/>
</div>
</t>
</templates>
问题在于这一行:
var $content = $(qweb.render('website.snippet_hello', {a:1}));
发生错误&#34;模板&#39; website.snippet_hello&#39;找不到&#34; 我注意到当我以管理员身份登录时(尚未尝试其他帐户),它运行良好。我在浏览器上注销时发生了错误。 请给我你的建议,谢谢!
答案 0 :(得分:1)
这是一个与过时的Odoo版本有关的老问题,但今天的答案仍然有用(Odoo v11 / 12/13):
Template Not found
可能在以下情况下发生:
通常,您在模板中将模板另存为/your_module/static/src/xml/snippet_template_filename.xml
,并且必须通过添加以下内容将此XML文件加载到/your_module/__manifest__.py
上:
'qweb': [
"static/src/xml/snippet_template_filename.xml",
],
或速记:
'qweb': [
"static/src/xml/*.xml",
],
您可以在odoo的“应用”菜单中安装/更新your_module,然后可以通过查看http://localhost:8069/web/webclient/qweb?mods=your_module
来验证模板是否已加载,
您还可以查看喜欢的浏览器网络检查器来检查http://localhost:8069/web/webclient/qweb?mods=[...]
请求,并检查是否正确加载了your_module
模组。
模板可以在您的js中使用,例如(Odoo> = v11):
odoo.define('your_module.NameOfYourJs', function (require) {
"use strict";
var QWeb = core.qweb;
[...]
var result = QWeb.render('website.snippet_hello', {a:1});
});
注意:要调试资产,您可以使用http://localhost:8069/web?debug=assets
。
希望这会有所帮助!