Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
4 ตอบกลับ
32536 มุมมอง

I'm trying to add change the text displayed on a template. The template allready inherits the inherits the main shop template and adds a feature. I want to change the text and add a div. But I cannot get the element. It throws the cannot find element error.

Template:

<template id="products" inherit_id="website_sale.products" priority="15">
	<xpath expr="//div[hasclass('o_wsale_products_main_row')]" position="before">
		<t t-if="some condition">
			<t t-if="some condition">
				<div class="col-12">
					<h5 class="mb-3">Categories</h5>

I want to replace the h5 element:

<xpath expr="//h5[@class='mb-3']" position="replace">

Tried also with:

<xpath expr="//h5[hasclass('mb-3')]" position="replace">

But it throws the same error

Element '<xpath expr="//h5[@class='mb-3']">' cannot be located in parent view



อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

Please try using the below line of code

example:


<template id="products" inherit_id="website_sale.products" priority="15">

    <xpatth expr = "//t[@t-if='some condition']//t[@t-if='some condition']//div[hasclass('col-12')]//h5" position="replace">


  //Your value


</xpath>



อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

Sometimes its better to give the complete xpath , here you need not mention the complete path, just try giving the div class oe_website_sale  before  o_wsale_products_main_row ,

<xpath expr="//div[hasclass('oe_website_sale')]/div[hasclass('o_wsale_products_main_row')]" position="before">    
    your conditions, div,  etc

</xpath>

                                                                    or 

<xpath expr="//div[hasclass('oe_website_sale')]" position="inside"> 

    your conditions, div,  etc
</xpath>


Hope it helps,

Thanks

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi ,

This h5 tag is in template "products" in your custom module

so to replace or to make any changes you have to inherit "Custom_module.products".

Hope this helps

regards

อวตาร
ละทิ้ง
ผู้เขียน

I do inherit the custom module template. But cannot even select the xpath node to replace the whole one.

Please make sure that you have added custom_module to depends in manifest

ผู้เขียน

It is. Working with odoo more than 3 years so lets assume that those basic things are correct. This is the 1st time I needed to change something that is in xpath, and I thought it will be as easy like you suggested but it doesn't work

Well that's how we make changes on an Xpath element. If you are still getting an error, then one have to look to the basics.I am sure that a person with over 3yr experience in odoo will be able to figure that out by himself.

Related Posts ตอบกลับ มุมมอง กิจกรรม
1
มี.ค. 24
4762
How to update existing product quantity? แก้ไขแล้ว
1
ต.ค. 20
13273
2
มี.ค. 24
2808
1
ม.ค. 24
1602
0
ต.ค. 23
1553