Skip to Content
Menu
This question has been flagged
4 Replies
3026 Views

Hi,

I want to add the default code to the website search bar dropdown, but i'm unsure how to target this particular template. 

The template is found here: addons/website/static/src/snippets/s_searchbar/000.xml

id="template"

t-tname="website.s_searchbar.autocomplete"

Any advice would be appreciated.


Thanks,

Ross.

Avatar
Discard
Best Answer

You can try below. I think it is what you are looking for.

Avatar
Discard

Add this code to your view...
<template id="assets_frontend" inherit_id="website_sale.assets_frontend">
<xpath expr="link[last()]" position="after">
<link rel="stylesheet" type="text/scss" href="/module_name/static/src/scss/style.scss"/>
</xpath>
</template>
For reports...
<template id="report_assets_common" inherit_id="web.report_assets_common">
<xpath expr="." position="inside">
<link rel="stylesheet" type="text/scss" href="/module_name/static/src/scss/style.scss"/>
</xpath>
</template>
@https://helixjumponline.com

Best Answer

Hii Ross,
If you want to target and add particular fields of your model , you can achieve this by adding this in xml,
id='your_custom_template'  inherit_id='Module_name.Template_ID'
//your functionality of code

and if you want to replace the whole template 
id='Module_name.Template_ID'  name='Name of Template'
//your functionality of code

I Hope this information will helpful for you.
Feel free for further Assistance on contact@geminatecs.com
Thank You,
Geminate Consultancy Services
w : www.geminatecs.com

Avatar
Discard
Best Answer

you can create a custom module and inherit the existing template to make the necessary modifications. Here's a step-by-step guide:

  1. Create a new custom module (e.g., custom_website) with the necessary module structure.

  2. Inside your custom module, create a new XML file (e.g., custom_searchbar_templates.xml) and define your modifications. The file should be placed in the static/src/snippets/ directory of your custom module.

  3. In the XML file, inherit the existing template (website.s_searchbar.autocomplete) using the template tag with the inherit_id attribute. Set the inherit_id value to the original template's id attribute.

  4. Within the inherited template, add your default code or modifications.

Here's an example of how your custom_searchbar_templates.xml file might look:

templates id="template" xml:space="preserve">
t t-extend="website.s_searchbar.autocomplete">
#!-- Inherit the existing template 
t t-inherit="website.s_searchbar.autocomplete">
#Add your modifications or default code 
            # For example, adding a default search suggestion 
t t-set="search_suggestion" t-value="'Your default search suggestion'"/>
/t>
/t>
/templates>


in your custom module's manifest file (__manifest__.py), make sure to include the XML file by adding it to the data section:

Avatar
Discard
Author Best Answer

Hi shubham shiroya,

I get the following error:

AssertionError: Element odoo has extra content: templates, line 3
XML:

xml version="1.0" encoding="utf-8"?>

odoo>

​templates id="template" xml:space="preserve">

​​t t-extend="website.s_searchbar.autocomplete">

​​t t-inherit="website.s_searchbar.autocomplete">

​​​ ​t t-set="search_suggestion"t-value="'Your default search suggestion'"/>

​​/t>

​/t>

​/templates>

/odoo>

Avatar
Discard

try this code:
<?xml version="1.0" encoding="UTF-8"?>
<templates>
<t t-extend="website.s_searchbar.autocomplete">
<!-- Add your modifications to the template here -->
<!-- For example, add a default code -->
<t t-jquery=".dropdown-item" t-operation="append">
<li class="dropdown-item" role="option" data-autocomplete-code="your_default_code">Your Default Code</li>
</t>
</t>
</templates>

Related Posts Replies Views Activity
0
Mar 23
1101
1
Mar 24
989
2
Mar 24
1855
2
Jul 23
2372
1
Feb 23
2238