Skip to Content
Menú
This question has been flagged
1 Respondre
344 Vistes

The Odoo website has a default 'Contact Us' button in its Navbar. 

--------------

|  Contact Us |

---------------

The existing template for 'Contact Us' button (id=website.header_call_to_action) is  located in webiste_templates.xml and it was coded as follows. 

<template id="website.header_call_to_action" inherit_id="website.placeholder_header_call_to_action" name="Header Call to Action" active="True">
<xpath expr="." position="inside">
<li t-attf-class="#{_item_class}">
<div t-attf-class="oe_structure oe_structure_solo #{_div_class}">
<section class="oe_unremovable oe_unmovable s_text_block" data-snippet="s_text_block" data-name="Text">
<div class="container">
<a href="/contactus" class="oe_unremovable btn btn-primary btn_cta">Contact Us</a>
</div>
</section>
</div>
</li>
</xpath>
</template>


I just wanted to add a new <span> element inside <a> tag of above template as follows. (I already have a module created with the name 'mytheme')

<template id="mytheme.header_call_to_action" inherit_id="website.header_call_to_action" name="Header Call to Action"
active="True">
<xpath expr="//a[hasclass('oe_unremovable')]" position="inside">
<span class="badge rounded-pill">Free</span>
</xpath>
</template>


 I added the above code('My Custom Call to Action') inside an xml file called 'custom_header.xml' which was inherited from 'website.layout'

<odoo>
<template id="header" inherit_id="website.layout" name="My Custom Header">
<xpath expr="//header" position="replace">
<nav>
<t t-call="website.navbar">
<t t-set="_nav_class" t-valuef="navbar"/>
<div class="container-fluid">
<!-- Brand -->
<t t-call="website.placeholder_header_brand">
<t t-set="_link_class" t-valuef="navbar-brand d-flex align-items-center"/>
</t>

<div class="d-flex align-items-center gap-2">
<!-- My Custom Call To Action -->
<t t-call="mytheme.header_call_to_action"/>
</div>
</div>
</t>
</nav>
</xpath>

</template>



<!-- My Custom Call To Action -->
<template id="mytheme.header_call_to_action" inherit_id="website.header_call_to_action" name="Header Call to Action"
active="True">
<xpath expr="//a[hasclass('oe_unremovable')]" position="inside">
<span class="badge rounded-pill">Free</span>
</xpath>
</template>
</odoo>



Here is the error message I received. Thanks in advance for your suggestions. 

Error message:

Error while render the template
ValueError: View 'mytheme.header_call_to_action' in website 1 not found
Template: website.layout
Avatar
Descartar
Best Answer

Hiii,

Since you're extending ( inherit_id ) the existing website.header_call_to_action, you should not call mytheme.header_call_to_action directly.

Instead, continue to use the original ID — it will include your change automatically.

Updated Code

<odoo> <template id = "mytheme.header_call_to_action" inherit_id = "website.header_call_to_action" name = "Header Call to Action" > <xpath expr = "//a[hasclass('oe_unremovable')]" position = "inside"> < span class = "badge rounded-pill" >Free </ span > </xpath> </template> <template id = "header" inherit_id = "website.layout" name = "My Custom Header"> <xpath expr = "//header" position = "replace"> <nav> <t t-call = "website.navbar"> <tt-set="_nav_class" t-valuef="navbar"/> <div class = "container-fluid"> <t t-call = "website.placeholder_header_brand" > <t t-set="_link_class" t-valuef="navbar-brand d-flex align-items-center"/> </t> <div class = "d-flex align-items-center gap-2"> <!-- Use the original ID --> <t t-call = "website.header_call_to_action"/> </div> </div> </t> </nav> </xpath> </template> </odoo>

I hope it is usefull

Avatar
Descartar
Related Posts Respostes Vistes Activitat
2
de juny 25
2011
3
d’abr. 25
2273
1
d’abr. 25
1391
1
de des. 24
1933
1
d’oct. 24
1616