默认¶
Odoo 会根据你安装的应用自动生成一些基本菜单项。例如,网站应用会向主菜单添加两个菜单项。这些菜单项链接到页面,而这些页面也会自动创建。
删除默认菜单项。
/website_airproof/data/menu.xml¶<!-- Delete: Contact us and Shop menu items -->
<delete
model="website.menu"
search="[('url','in', ['/contactus', '/shop']), ('website_id', '=', 1)]" />
新窗口¶
在新标签页中打开链接的 URL。
<record id="..." model="website.menu">
<field name="new_window" eval="True" />
</record>
外部链接¶
添加指向外部网站的链接。
<record id="..." model="website.menu">
<field name="url">https://www.odoo.com</field>
</record>
锚点¶
链接到页面的特定部分。
<record id="..." model="website.menu">
<field name="url">/about-us#our-team</field>
</record>
自定义模板¶
创建您自己的模板并将其添加到列表中。
布局
/website_airproof/views/website_templates.xml¶<template id="s_mega_menu_airproof" name="Airproof" groups="base.group_user">
<section class="s_mega_menu_airproof o_cc o_cc1 pt40">
<!-- Content -->
</section>
</template>
选项
使用以下代码,在网站构建器中为你的新自定义巨型菜单添加选项。
/website_airproof/static/src/website_builder/mega_menu_option.xml¶<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">
<t t-name="website_airproof.MegaMenuOption" t-inherit="website.MegaMenuOption" t-inherit-mode="extension">
<xpath expr="//BuilderSelect[@id="'mega_menu_template_opt'"]" position="inside">
<BuilderSelectItem
title.translate="Airproof"
actionParam="{
view: `website_airproof.s_mega_menu_airproof`,
templateClass: 's_mega_menu_airproof',
}">
<Img class="'w-75 mx-auto my-3'" src="'/website_airproof/static/src/img/wbuilder/template-header-opt.svg'" />
</BuilderSelectItem>
</xpath>
</t>
</templates>
本站校对说明
本篇《Odoo 20.0 documentation》翻译自 Odoo 20.0 企业版官方文档。开发章节的术语统一为:model 译为「模型」、field 译为「字段」、view 译为「视图」、record rule 译为「记录规则」、inheritance 译为「继承」。文中代码示例已对照 20.0 源码核对;Odoo 各版本间 API 有变动,17 及更早版本的写法在 20.0 上可能直接报错,跨版本迁移时请以本页示例为准。涉及模块骨架生成、升级脚本与测试的运行方式,可在本站开发专题中查阅。如与官方英文版表述不一致,以 odoo.com 官方源码与文档为准。
内容源自 Odoo S.A. 官方文档,依 CC BY-SA 4.0 许可翻译与校对,版权归 Odoo S.A.。本站为第三方中文文档站点,非 Odoo 官方网站。遇到与官方表述冲突之处,请以 odoo.com 官方文档 为准;版本选型可参考 社区版与企业版对比。