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

I have a qweb setup like this: 

file 'a.xml':

<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
    <t t-name="templatename">
        ...          </t>     
</templates>
file 'b.xml':

<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
    <t t-extend="templatename">
        *** CONTENT TO REPLACE ***          
    </t>     
</templates>
How do I replace that content?
I tried using both the deprecated t-extends and the up-to-date t-inherit methods: 
<t t-extend="templatename">
    <xpath expr="..." position="replace">
        *** REPLACEMENT CONTENT ***
    </xpath>
</t>

<t t-inherit="moduleoftemplatename.templatename" t-inherit-mode="extension"> <xpath expr="..." position="replace"> *** REPLACEMENT CONTENT *** </xpath> </t>

But neither of these work, as these inherit the template specified in 'a.xml', so xpath can't find the content from 'b.xml' it's looking for. 
How can I solve this given that I can't change content in 'a.xml' or 'b.xml'?

頭像
捨棄
最佳答案

Hi, 

Here is a simple example: 

<t t-extend="OrderReceipt">
<t t-jquery=".pos-receipt-order-data" t-operation="append">
<t t-if="receipt.l10n_fr_hash !== false">
<div style="word-wrap:break-word;"><t t-esc="receipt.l10n_fr_hash"/></div>
</t>
</t>
</t>


OrderReceipt is the name of a template. 

pos-receipt-order-data is a class of an element inside the temp OrderReceipt
then we choose t-operation="append".

In your case, you do the same but with t-operation="replace"

Hope this helps.
Regards.

頭像
捨棄
作者

I think you might have understood what I need. The way your example would work is that it would replace the entire 'pos-receipt-order-data' element, which is not what I need.

Porting my problem to your solution, What I need is ideally replacing only the '<div style="word-wrap:break-word;">'. The original template (OrderReceipt) should not be altered in any way.

I would also be okay with replacing the entire '<t t-extend="OrderReceipt">...</t>' altogether, but I can't find a way to inherit this extension.

Hello,

my example is just to show you how to replace since in your question you mentioned that you do not know how to do it. The answer to that is simple with t-operation="replace". this answers your Question dude.

We don't use Xpath in Qweb :)

Now since you know how to do replace operations, it's up to you to get the element you want to replace.

Good luck!

相關帖文 回覆 瀏覽次數 活動
2
12月 22
22828
3
11月 19
7653
1
1月 17
4277
2
1月 24
1358
2
12月 21
22310