Ir al contenido
Menú
Se marcó esta pregunta
4 Respuestas
32374 Vistas

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



Avatar
Descartar
Mejor respuesta

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>



Avatar
Descartar
Mejor respuesta

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

Avatar
Descartar
Mejor respuesta

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

Avatar
Descartar
Autor

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

Autor

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.

Publicaciones relacionadas Respuestas Vistas Actividad
1
mar 24
4681
1
oct 20
13219
2
mar 24
2756
1
ene 24
1572
0
oct 23
1515