I'm trying to create a custom snippet on Odoo (version 18, it's important). I'm following this example. The source code is here
Unfortunately, I'm unable to make the snippet appear on the version 18 website builder edit panel.
I tried with the version 17 and it worked without problem. Here a screenshot on the version 17.
I tried multiple xpath including the one found on the documentation of the version 18 and it doesn't work neither. I either have an error or no snippets showing on the edit panel.
<xpath expr="//t[@t-snippet='website.s_banner']" position="before">
<xpath expr="//div[@id='snippet_effect']//t[@t-snippet][last()]" position="after">
<xpath expr="//div[@id='snippet_structure']/div[@class='o_panel_body']" position="inside">
All of them give me the error
Element '<xpath expr="//div[@id='snippet_structure']">' cannot be located in parent view
The xpath is into the xml inheriting website.snippets
.
<template id="snippets" inherit_id="website.snippets">
<xpath expr="//*[@id='snippet_structure']" position="inside"> <!-- No error but nothing appear -->
<t t-snippet="website_oxp_2023_ard.s_weather" string="Weather Forecast" t-thumbnail="/website_oxp_2023_ard/static/src/img/s_weather.svg"/>
</xpath>
</template>
Does anyone know how to add a snippet to Odoo version 18 ?
Try to to add your custom snippet after an existing one (ex: s_parallax):
<xpath expr="//t[@t-snippet='website.s_parallax']" position="after">
<t t-snippet="mycustom_module.s_mycustom_snippet" t-thumbnail="/website/static/src/img/snippets_thumbs/s_website_form.svg"/>
</xpath>
...more info can be found in addons/website/tests/test_ui.py
OR add it after the last existing snippet:
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="my_snippet" inherit_id="website.snippets" priority="8">
<xpath expr="//div[@id='snippet_content']//t[@t-snippet][last()]">
<t t-snippet="mycustom_module.mycustom_snippet"/>
</xpath>
</template>
</odoo>