Skip to Content
Menu
This question has been flagged
3 Replies
7765 Views

I am learning OWL. I created custom module 'owl_funn'. I want to extend Component.

I want to add template to my custom Component, but I'm getting error:

Uncaught Promise > Template owl_funn.MyComponent does not exist

My component.js looks like:

/** @odoo-module **/

const { Component } = owl;
const { whenReady } = owl.utils;

class MyComponent extends Component {
};

whenReady().then(() => {
const app = new MyComponent();
app.mount(document.body);
});

MyComponent.template = 'owl_funn.MyComponent'

comp.xml looks like:






Welcome to Odoo 2
        



__manifest__.py looks like:

{
"name": "owl_funn",
"summary": "Provides an example module for OWL.",
"description": "Provides an example module for OWL.",
"author": "Martinez",
"website": "http://www.example.com",
"category": "Tutorials",
"depends": ["base", "web"],
"demo": [],
"data": [],
"assets": {
"web.assets_qweb": [
"owl_funn/static/src/xml/comp.xml"
],
"web.assets_backend": [
"/owl_funn/static/src/js/component.js"
]
}
}

Files in __manifest__.py are ok, because when I changed names of files in __manifest__.py then I got error that those files no exists.


I don't want to write template xml inline, because I read that it is not good practice.

Why my js file don't see xml template?


Avatar
Discard

i have the same problem, any help ?

Best Answer

After a lot of headaches, I finally figured out that my problem is that I hadn't given my template the owl="1" attribute in the definition.

In my case the structure would be this:

template_file.xml (Note: For some reason I can't make the xml code visible, so I've removed some symbols)


xml version="1.0" encoding="UTF-8"

template xml:space="preserve"

    t t-name="module.Component" owl="1"

       //QWEB CONTENT

    /t

/template


component_file.js


/** @odoo-module **/

const { Component } = owl;

export default class ComponentModel extends Component {
    setup() {
        super.setup(...arguments);
    }
};

ComponentModel.template = 'module.Component';


Now it only remains to properly import the files using the __manifest__.py


'assets': {
    'web.assets_qweb': [
        'module/static/src/**/*.xml',
    ],
    'web.assets_backend': [
        'module/static/src/**/*.js',
    ],
}

I hope it works for you...

Avatar
Discard
Best Answer

Hello, I have the same issue. Did you find a solution ? Thank you.

Avatar
Discard
Best Answer

I am having the same issue. Any help would be much appreciated.

Avatar
Discard
Related Posts Replies Views Activity
1
Feb 24
1010
1
Jan 24
6348
2
Dec 23
2002
0
Jul 23
122
1
Feb 23
2370