简体   繁体   English

未找到 Qweb 模板 - Odoo v8

[英]Qweb template not found - Odoo v8

I'm developing a website with Odoo v8.我正在使用 Odoo v8 开发一个网站。 I want to write a snippet that its struct is load by javascript.我想写一个片段,它的结构是由 javascript 加载的。 Bellow are my code ... Firstly, I have a snippet struct:波纹管是我的代码......首先,我有一个片段结构:

<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>

Then I have a little javascript code to render snippet content:然后我有一些 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);
        },
    });

})();

Then I have a QWeb template to display my struct content (filename: snippet_template_filename.xml):然后我有一个 QWeb 模板来显示我的结构内容(文件名: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>

Problem is this line:问题是这一行:

var $content = $(qweb.render('website.snippet_hello', {a:1}));

occurred error that "Template 'website.snippet_hello' not found" I noticed that when I logged in as Admin (haven't tried another account), it works well.出现“找不到模板‘website.snippet_hello’”的错误我注意到当我以管理员身份登录时(没有尝试过其他帐户),它运行良好。 It just occurred error when I logged out on my browser.当我在浏览器上注销时,它只是发生了错误。 Please let me your advice, thanks!请给我您的建议,谢谢!

This is an old question related to an obsolete Odoo's version but answer is still relevant today (Odoo v11/12/13) :这是一个与过时的 Odoo 版本相关的老问题,但今天的答案仍然相关(Odoo v11/12/13):

Template Not found could occur when: Template Not found可能在以下情况下发生:

  • template is not loaded模板未加载
  • template names are not equals between your js and your template's xml files. js 和模板的 xml 文件之间的模板名称不相等。 Templates names are case sensitive.模板名称区分大小写。

Loading a template:加载模板:

Usually you save your templates in your project as /your_module/static/src/xml/snippet_template_filename.xml , and you must load this xml file on /your_module/__manifest__.py by adding:通常,您将项目中的模板保存为/your_module/static/src/xml/snippet_template_filename.xml ,并且您必须通过添加以下内容将这个 xml 文件加载到/your_module/__manifest__.py

 'qweb': [
        "static/src/xml/snippet_template_filename.xml",
    ],

or shorthand:或简写:

 'qweb': [
        "static/src/xml/*.xml",
    ],

You install/update your_module in odoo's App menu, then you can verify that your template is loaded by looking at http://localhost:8069/web/webclient/qweb?mods=your_module , it should returns your templates.您在 odoo 的 App 菜单中安装/更新 your_module,然后您可以通过查看http://localhost:8069/web/webclient/qweb?mods=your_module来验证您的模板是否已加载,它应该返回您的模板。

You can also look at favorite browser network inspector to check the http://localhost:8069/web/webclient/qweb?mods=[...] request and checks that in mods your_module is loaded properly.您还可以查看最喜欢的浏览器网络检查器来检查http://localhost:8069/web/webclient/qweb?mods=[...]请求并检查 mods your_module是否正确加载。

Template can be used in your js like in this (Odoo >= v11):模板可以像这样在你的 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});

});

Note: to debug assets you can use http://localhost:8069/web?debug=assets .注意:要调试资产,您可以使用http://localhost:8069/web?debug=assets

Hope this helps!希望这有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM