İçereği Atla
Menü
Bu soru işaretlendi
1 Cevapla
7398 Görünümler

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'?

Avatar
Vazgeç
En İyi Yanıt

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.

Avatar
Vazgeç
Üretici

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!

İlgili Gönderiler Cevaplar Görünümler Aktivite
2
Ara 22
22828
Qweb Inheritance Çözüldü
3
Kas 19
7653
1
Oca 17
4276
2
Oca 24
1358
2
Ara 21
22310