Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
7391 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Autore

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!

Post correlati Risposte Visualizzazioni Attività
2
dic 22
22824
3
nov 19
7645
1
gen 17
4273
2
gen 24
1352
2
dic 21
22303