Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
1 Beantwoorden
7350 Weergaven

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
Annuleer
Beste antwoord

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
Annuleer
Auteur

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!

Gerelateerde posts Antwoorden Weergaven Activiteit
2
dec. 22
22763
3
nov. 19
7590
1
jan. 17
4239
2
jan. 24
1331
2
dec. 21
22247