Odoo Help

3

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

By
Anil R. Kesariya (Jupical Technologies)
on 5/26/17, 5:07 AM 4,808 views

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

2

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>

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.

Anil R. Kesariya (Jupical Technologies)
on 5/26/17, 6:11 AM

use this one <templates> instead of <template>

Prashant Panchal (ppa)
on 5/26/17, 6:23 AM

try this one

<templates xml:space="preserve">

<t t-extend="UserMenu">

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

</t>

</templates>

Prashant Panchal (ppa)
on 5/26/17, 6:29 AM

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

Anil R. Kesariya (Jupical Technologies)
on 5/26/17, 6:30 AM

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

Prashant Panchal (ppa)
on 5/26/17, 6:33 AM

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

Anil R. Kesariya (Jupical Technologies)
on 5/26/17, 6:38 AM

load in 'qweb': [],

Prashant Panchal (ppa)
on 5/26/17, 6:39 AM

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

Anil R. Kesariya (Jupical Technologies)
on 5/26/17, 8:07 AM

I appreciate your help, thanks.

Anil R. Kesariya (Jupical Technologies)
on 5/26/17, 8:07 AM

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

Prashant Panchal (ppa)
on 5/26/17, 8:12 AM

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

Anil R. Kesariya (Jupical Technologies)
on 5/26/17, 8:14 AM

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

});

Prashant Panchal (ppa)
on 5/26/17, 8:21 AM

Yes, now loaded :) working perfectly.

Anil R. Kesariya (Jupical Technologies)
on 5/26/17, 8:38 AM

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

Prashant Panchal (ppa)
on 5/26/17, 8:39 AM

Cheers!

Anil R. Kesariya (Jupical Technologies)
on 5/26/17, 8:48 AM
2

Anil R. Kesariya (Jupical Technologies)

--Anil R. Kesariya (Jupical Technologies)--
6127
| 7 6 8
Rajkot, India
--Anil R. Kesariya (Jupical Technologies)--

Odoo Techno Functional Expert

* Engaged with odoo since May - 2012.

* Customise existing module or develop new module base on customer requirement.

* Played key developer role in many past and running projects.

* Expert in requirement gathering of business and transforming requirement into odoo platform.

* Major expertise in core modules, database, report development and theme development.

* Integration expert.


Linkedin  : https://in.linkedin.com/in/anil-kesariya-97b20a66


Anil R. Kesariya (Jupical Technologies)
On 5/26/17, 8:47 AM

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

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

Minh Nguyen
on 1/9/18, 4:57 AM

In which version of odoo, you are applying this?

Anil R. Kesariya (Jupical Technologies)
on 1/9/18, 5:19 AM
1

Mohammed Amal

--Mohammed Amal--

2024
| 5 3 7
Malappuram, India
--Mohammed Amal--

Email : mohammedamal.n@gmail.com

Mohammed Amal
On 5/26/17, 5:32 AM

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

Thanks Mohammed for quick response, any sample example?

Anil R. Kesariya (Jupical Technologies)
on 5/26/17, 5:38 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register

Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)

Stats

Asked: 5/26/17, 5:07 AM
Seen: 4808 times
Last updated: 8/21/18, 11:53 PM