跳至內容
選單
此問題已被標幟
18 回覆
36919 瀏覽次數

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

頭像
捨棄
最佳答案

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.

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!

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

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

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

作者 最佳答案

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

作者

In which version of odoo, you are applying this?

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

最佳答案

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

頭像
捨棄
作者

Thanks Mohammed for quick response, any sample example?

相關帖文 回覆 瀏覽次數 活動
1
8月 24
1719
1
3月 24
1344
2
12月 22
32080
2
11月 21
8200
1
7月 19
5159