Help

3

[odoo10] : How to inherit <templates> of web module?

Hello Everyone,

How to inherit the template which is defined inside of <templates> in main web module

I've know that how to inherit the template of which are defined with <template> tag. individually.

I want find the mystery behind the <templates> in which number of template could be defined together.

Now, main GOAL to to inherit the main <templates> which is defined inside the web module as,

<templates id="template" xml:space="preserve">
-----
</templates>  

Any idea about this appreciated,

Regards,

Anil

Avatar
Discard
3 Answers
5
Best Answer

Hello,


Please Try Following Demo: 

--------------------------

This is main template:


<template id="template" xml:space="preserve">
    <t t-name="DemoExample">
        <div class="demo-one">
            <p>odoo</p>
        </div>
    </t>
</template>


How To Inherit
----------------------
Template file :-> demo_template.xml

<template id="template" xml:space="preserve">
    <t t-name="DemoExample" t-extend="DemoExample">
        <t t-jquery='.demo-one' t-operation='replace'>
            <p>Your Company Name</p>
        </t>
    </t>
</template>

-----------------------------------------------------
<!- Loaded XML files inside java script code -->
-----------------------------------------------------
JS file :-->  demo_example.js

-------------------------------------------------------------------------
put the following JS Code in demo_example.js file:
-------------------------------------------------------------------------

odoo.define('module_name.name_of_fetures', function (require) {
'use strict';
var core = require('web.core');
var ajax = require('web.ajax');
var qweb = core.qweb;
ajax.loadXML('/module_name/static/src/xml/demo_template.xml', qweb);
});

-----------------------------------
Loading of Javascript file 
-----------------------------------
<template id="demo_example_ext_js" name="Demo Example Ext Js" inherit_id="web.assets_backend">
    <xpath expr="." position="inside">
        <script type="text/javascript" src="/module_name/static/js/demo_example.js"></script>
    </xpath>
</template>
19 Comments
Avatar
Discard

I followed as you explained. using t-extend and j-query

Tried this one NOT working

<template>

<t t-name="web.UserMenu" t-extend="web.UserMenu">

<t t-jquery='.dropdown-menu' t-operation='replace'/>

</t>

</template>

Tried this one NOT working

<template>

<t t-name="UserMenu" t-extend="UserMenu">

<t t-jquery='.dropdown-menu' t-operation='replace'/>

</t>

</template>

Not getting any error, but doesn't gives result as expected.

use this one <templates> instead of <template>

try this one

<templates xml:space="preserve">

<t t-extend="UserMenu">

<t t-jquery=".dropdown-menu" t-operation="replace"/>

</t>

</templates>

When i use <templates> instead <template>, than xml file not loading, getting error.

how to load xml file can you explain ? you can load xml file by javascript or in __openerp__.py or __manifest__.py

I am loading XML file inside __openerp__.py under data = []

load in 'qweb': [],

@prashant : I loaded that XML file in 'qweb':[] instead of data. but still doesn't working :)

I appreciate your help, thanks.

create you file with templates code and put in this directory like

module > static > src > xml > file.xml

and you can use like : 'qweb': ['static/src/xml/file.xml'], and then after upgrade the module

Yes prashant, I followed the same file path and upgraded module, but no error, but it not functioning.

Create one js fille and put the code following code:

odoo.define('module_name.js_file_name', function (require) {

'use strict';

var core = require('web.core');

var ajax = require('web.ajax');

var qweb = core.qweb;

ajax.loadXML('/maodule/static/src/xml/file.xml', qweb);

});

Yes, now loaded :) working perfectly.

yeah..............................

Cheers!

Avatar
LaoThai
-

Hi Anil, How can I add function print reciept for this button we just created?

Avatar
Dasadiya Chaitanya
-

Good Answer @Prashant your answer is really helping me a lot..

Avatar
Prashant Panchal (ppa)
-

Yeah,

Thank you

Cheers!

Hi there,

I'm trying to accomplish this in odoo 12 but not working, nothing changes but no errors instead.

Do you know if should I change something in the code for odoo12?

Thank you

5
Best Answer

Hi All,

Here I am writing complete solution which works for me, all credit goes to @ Prashant Panchal, Finally the long discussion on the solution was fruitful. 

Sample example.

Template file   : header_template.xml                   

<template id="template" xml:space="preserve">
    <t t-name="UserMenu" t-extend="UserMenu">
        <t t-jquery='.dropdown-menu' t-operation='replace'/>
    </t>
</template>
<!- Loaded XML files inside java script code -->


Javascript file qweb_template.js

odoo.define('yourmodulename.your_feature_name', function (require) {
'use strict';
var core = require('web.core');
var ajax = require('web.ajax');
var qweb = core.qweb;
ajax.loadXML('/yourmodulename/static/src/xml/header_template.xml', qweb);
});


Loading of Javascript file 

<template id="extended_libs" name="extended libs" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
    <script type="text/javascript" src="/yourmodulename/static/js/qweb_template.js"></script>
    </xpath>
</template>


Regards,

Anil kesariya

5 Comments
Avatar
Discard
Avatar
Minh Nguyen
-

I have same problem like you, i want inherit templates from:

<templates id="template" xml:space="preserve">

<t t-name="UserMenu.Actions">

<li><a href="#" data-menu="documentation">Documentation</a></li>

<li><a href="#" data-menu="support">Support</a></li>

<li class="divider"/>

<li><a href="#" data-menu="settings">Preferences</a></li>

<li><a href="#" data-menu="account">My Odoo.com account</a></li>

<li><a href="#" data-menu="logout">Log out</a></li>

</t>

</templates>

in module web to add 1 more <li> to this list, can u suggest me anything? I tried to make it like you but it didn't word for me.

Thanks,

Minh

In which version of odoo, you are applying this?

Avatar
LaoThai
-

Hi Anil, how can i add function print receipt for this button we just created?

@LaoThai, I don't understand your question. please provide some more information.

Hi there,

I'm trying to accomplish this in odoo 12 but not working, nothing changes but no errors instead.

Do you know if should I change something in the code for odoo12?

Thank you

1
Best Answer

Anything inside templates can be extended using t-extend and t-jquery.

1 Comment
Avatar
Discard

Thanks Mohammed for quick response, any sample example?