【发布时间】:2016-10-26 02:27:55
【问题描述】:
我正在使用 Odoo v8 开发一个网站。我想写一个sn-p,它的结构是由javascript加载的。下面是我的代码... 首先,我有一个 sn-p 结构:
<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 代码来呈现 sn-p 内容:
(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 模板来显示我的结构内容(文件名:sn-p_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}));
出现“找不到模板'website.sn-p_hello'”的错误 我注意到当我以管理员身份登录时(没有尝试过其他帐户),它运行良好。当我在浏览器上注销时,它只是发生了错误。 请给我您的建议,谢谢!
【问题讨论】:
标签: javascript odoo-8 qweb odoo-website