You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Odoo 18自定义Snippet添加失败:无法在网站编辑器显示

解决Odoo 18自定义Snippet无法显示的问题

Odoo 18对网站构建器的Snippets面板结构做了重构,原有的#snippet_structure节点已被移除,这是导致你原有XPath失效的核心原因。以下是两种可行的解决方案:

方案1:添加到现有分类(如Structure)

使用基于类和文本内容的XPath定位到目标分类的内容容器,将自定义Snippet插入其中:

<template id="snippets" inherit_id="website.snippets">
    <!-- 定位到Structure分类下的Snippet列表容器 -->
    <xpath expr="//div[contains(@class, 'o_we_snippet_category') and .//h5[text()='Structure']]/div[contains(@class, 'o_we_snippet_list')]" position="inside">
        <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>

方案2:创建自定义分类组

如果不想依赖现有分类,可直接在Snippets面板中新增一个自定义分类,更便于管理自己的Snippet:

<template id="snippets" inherit_id="website.snippets">
    <xpath expr="//div[@id='snippet_panel']" position="inside">
        <div class="o_we_snippet_category">
            <h5 class="o_we_snippet_category_title">自定义组件</h5>
            <div class="o_we_snippet_list">
                <t t-snippet="website_oxp_2023_ard.s_weather" string="Weather Forecast" t-thumbnail="/website_oxp_2023_ard/static/src/img/s_weather.svg"/>
            </div>
        </div>
    </xpath>
</template>

额外注意事项

  • 确保你的s_weather Snippet模板已正确定义,根元素需包含data-snippet属性,示例结构如下:
    <template id="s_weather" name="Weather Forecast">
        <section data-snippet="website_oxp_2023_ard.s_weather" class="s_weather">
            <!-- 你的Snippet内容 -->
        </section>
    </template>
    
  • 修改代码后,需重启Odoo服务,更新对应模块,然后清除浏览器缓存并刷新网站构建器页面。

内容的提问来源于stack exchange,提问作者olive007

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.16 15:00:59