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

Odoo 9文章列表分页后面包屑显示异常问题求助

解决Odoo 9文章列表分页后面包屑消失的问题

我碰到过不少类似的Odoo页面导航问题,你这个情况很典型——第一页面包屑显示正常,但切到第二、第三页就直接隐藏了,咱们先拆解问题根源,再给你修复方案。

问题出在哪?

看你贴的模板代码,核心问题在菜单匹配的逻辑上:

<t t-set="bc_item" t-value="request.env['website.menu'] .search([('url', '=', request.httprequest.path)], limit=1)"/>

你是直接用request.httprequest.path去匹配菜单的url字段,但分页时页面URL会带上?page=2这类查询参数,虽然request.httprequest.path还是原路径,但Odoo的菜单url是不带分页参数的,这时候search就找不到对应的菜单项,bc_item为空,面包屑的<ol>容器就不会渲染,自然就看不到了。

修复方案(两种可选)

方案1:用Odoo自带的当前菜单属性(推荐)

Odoo的request.website对象里有个current_menu属性,它会自动识别当前页面对应的菜单,不管URL有没有分页参数,直接用这个最稳妥:

<odoo>
    <template id="breadcrumb" name="Breadcrumb snippet">
        <!-- 直接获取当前页面绑定的菜单 -->
        <t t-set="bc_item" t-value="request.website.current_menu"/>
        <!-- If so, create the breadcrumbs -->
        <ol t-if="bc_item" class="breadcrumb">
            <!-- Parents -->
            <t t-foreach="bc_item.get_parents(True)" t-as="step">
                <li t-if="step.url or step_first">
                    <a t-att-href="step.url or (step_first and '/')">
                        <t t-if="step_first and not step.url"> Home </t>
                        <t t-if="not step_first and step.url">
                            <t t-esc="step.name_get()[0][1]"/>
                        </t>
                    </a>
                </li>
            </t>
            <!-- Current -->
            <li class="active" t-esc="bc_item.name_get()[0][1]"/>
        </ol>
    </template>
</odoo>

方案2:模糊匹配URL路径

如果因为某些原因不能用current_menu,可以修改查询逻辑,忽略URL的参数部分,用模糊匹配找到对应菜单:

<odoo>
    <template id="breadcrumb" name="Breadcrumb snippet">
        <!-- 提取当前页面的基础路径 -->
        <t t-set="current_base_path" t-value="request.httprequest.path"/>
        <!-- 先精确匹配,没找到就模糊匹配 -->
        <t t-set="bc_item" t-value="request.env['website.menu'].search([('url', '=', current_base_path)], limit=1)"/>
        <t t-if="not bc_item">
            <t t-set="bc_item" t-value="request.env['website.menu'].search([('url', '=like', current_base_path + '%')], limit=1)"/>
        </t>
        <!-- If so, create the breadcrumbs -->
        <ol t-if="bc_item" class="breadcrumb">
            <!-- Parents -->
            <t t-foreach="bc_item.get_parents(True)" t-as="step">
                <li t-if="step.url or step_first">
                    <a t-att-href="step.url or (step_first and '/')">
                        <t t-if="step_first and not step.url"> Home </t>
                        <t t-if="not step_first and step.url">
                            <t t-esc="step.name_get()[0][1]"/>
                        </t>
                    </a>
                </li>
            </t>
            <!-- Current -->
            <li class="active" t-esc="bc_item.name_get()[0][1]"/>
        </ol>
    </template>
</odoo>

效果验证

替换模板后,刷新页面再切换分页,面包屑应该就能一直正常显示了。第一种方案更贴合Odoo的原生逻辑,稳定性更高,优先推荐。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 08:56:51