콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
18 답글
37073 화면

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
1798
1
3월 24
1385
2
12월 22
32195
2
11월 21
8253
1
7월 19
5222