跳至内容
Odoo 菜单
  • 登录
  • 免费试用
  • 应用程序
    财务
    • 会计
    • 发票
    • 费用
    • 电子表格 (BI)
    • 文档
    • 电子签名
    销售
    • 客户关系管理
    • 销售
    • POS 销售点管理-零售
    • POS 销售点管理 - 餐厅
    • 订阅
    • 租赁
    网站
    • 网站设计
    • 电子商务
    • 博客
    • 论坛
    • 在线客服
    • 在线学习
    供应链
    • 库存
    • 制造
    • 产品生命周期
    • 采购
    • 维护保养
    • 品控
    人力资源
    • 员工
    • 招聘
    • 休假
    • 评价
    • 内部推荐
    • 车队
    营销
    • 社媒营销
    • 电邮营销
    • 短信营销
    • 近期活动
    • 营销自动化
    • 网上调查
    服务
    • 项目管理
    • 工时单
    • 现场服务
    • 服务台
    • 排期
    • 预约
    生产力
    • 讨论
    • 批核
    • IoT物联网
    • VoIP
    • 知识库
    • WhatsApp
    第三方应用软件 Odoo 定制 Odoo云端平台
  • 行业
    零售
    • 书店
    • 服装店
    • 家具店
    • 食品杂货店
    • 五金店
    • 玩具店
    餐饮与酒店服务
    • 酒吧及酒馆
    • 餐厅
    • 快餐
    • 民宿
    • 饮品分销商
    • 酒店
    房地产
    • 房地产代理
    • 建筑师事务所
    • 建造业
    • 地产管理
    • 园艺
    • 业主协会
    咨询
    • 会计师事务所
    • Odoo合作伙伴
    • 市场推广公司
    • 律师事务所
    • 人才招聘
    • 审核 & 认证
    制造
    • 纺织
    • 金属
    • 家具
    • 食品
    • 啤酒厂
    • 企业礼品
    保健与健身
    • 体育俱乐部
    • 眼镜店
    • 健身中心
    • 健康从业者
    • 药房
    • 发型屋
    商贸服务
    • 维修人员
    • IT 硬件及支持
    • 太阳能系统
    • 鞋匠
    • 清洁服务
    • 暖通空调服务
    其他
    • 非营利组织
    • 环境机构
    • 广告牌租赁
    • 摄影服务
    • 自行车租赁
    • 软件经销商
    浏览所有行业
  • 社区
    学习
    • 教学视频
    • 文档
    • 认证
    • 培训
    • 博客
    • 播客
    赋能教育
    • 教育计划
    • Scale Up! 商业游戏
    • 参观Odoo
    获取软件
    • 下载
    • 版本对比
    • 发布
    合作
    • Github
    • 论坛
    • 近期活动
    • 翻译
    • 成为合作伙伴
    • 合作伙伴服务
    • 注册您的会计事务所
    获取服务
    • 寻找合作伙伴
    • 查找会计服务
    • 预约顾问咨询
    • 安装及推行服务
    • 客户参考
    • 支持
    • 升级
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    获取演示
  • 定价
  • 技术支持

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • 客户关系管理
  • e-Commerce
  • 会计
  • 库存
  • PoS
  • 项目
  • MRP
All apps
只限注册用戶才可与社群互动。
所有帖文 人 徽章
标签 (查看所有)
odoo accounting v14 pos v15
关于此论坛区
只限注册用戶才可与社群互动。
所有帖文 人 徽章
标签 (查看所有)
odoo accounting v14 pos v15
关于此论坛区
帮助

OWL Component Not Rendering in Custom Layout (Odoo 18) — Likely XML Template Issue

订阅

此帖文有活动时,接收通知

此问题已终结
javascriptdevelopmentprojectdebug
1 回复
3518 查看
形象
Kvrolito

🔧 OWL Component Not Rendering in Custom Layout (Odoo 18) — Likely XML Template Issue

Hello everyone,

I'm currently working on Odoo 18 and trying to render a simple OWL component inside a custom dashboard layout. Despite successfully loading all related JS files, the component does not appear in the UI, and I suspect the issue lies in how the XML template is handled.

📁 Project Structure

My layout is defined in:

my_module/static/src/views/dashboard_page_layout.xml

My JS files are located in:

my_module/static/src/js/

📦 Files

HelloBox.js

/** @odoo-module **/

import { Component, xml } from '@odoo/owl';

export class HelloBox extends Component {}

HelloBox.template = xml`
  <div class="hello-box">
    <h1><t t-esc="props.title"/></h1>
    <button t-on-click="sayHello">Click me</button>
  </div>
`;

HelloBox.props = {
  title: { type: String },
};

HelloBox.prototype.sayHello = function () {
  alert('Hello from OWL!');
};

HelloBox.xml

<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
  <t t-name="my_module.HelloBox" owl="1">
    <div class="p-3">
      <p><t t-out="props.title"/></p>
      <button>Click me</button>
    </div>
  </t>
</templates>

init_owl.js

/** @odoo-module **/

import { mount, whenReady } from '@odoo/owl';
import { HelloBox } from './HelloBox';

whenReady(() => {
  const root = document.getElementById('hello-box-root');
  console.log('Mounting HelloBox in:', root);

  if (root) {
    mount(HelloBox, {
      target: root,
      props: { title: 'Witaj z OWL!' },
    });
  }
});

In my dashboard_page_layout.xml, I manually placed:

<div id="hello-box-root"></div>

🧩 Problem Focus

✅ The JS loads successfully, console.log confirms the mount target exists, and the component code is correct.

❌ The XML template seems to be the weak point — I suspect it may not be loaded or registered correctly, despite being included in the assets.

In some cases I even get:

TypeError: Cannot read properties of undefined (reading 'defaultProps')

Which usually indicates OWL is trying to mount an incomplete or undefined component — possibly due to the XML template not being properly compiled or injected.

📜 __manifest__.py

'assets': {
    'web.assets_frontend': [
        'my_module/static/src/js/HelloBox.xml',
        'my_module/static/src/js/HelloBox.js',
        'my_module/static/src/js/init_owl.js',
    ],
},

I've also tried adding the XML to web.assets_qweb, web.assets_backend, and changing the load order, but the issue remains.

🙏 What I'm Looking For

  • How should XML templates be properly registered in OWL/Odoo 18 when working with web.assets_frontend?
  • Do I need to explicitly register or reference them in a different way?
  • Is there anything missing to make this work with t-name="my_module.HelloBox"?
  • Is using xml\template`` inside the JS file the preferred approach instead?

Any guidance would be highly appreciated.

Thanks in advance for your support!

Karol


0
形象
丢弃
Kvrolito
编写者


Unfortunately, that’s not the case. While I’ve successfully used inline XML templates, that’s not the approach I want to take. I’d like to define my OWL templates in separate XML files so that I can pass props and create dynamic, reusable components.

🧩 Template File: owl_templates.xml

<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
  <t t-name="my_folder.owl_main_component" owl="1">
    <div>
      <h3>This is rendered using OWL</h3>
    </div>
    <!-- I intentionally commented out the <t> tag earlier to test loading -->
  </t>
</templates>

🧠 Component File: owl_component.js

/** @odoo-module **/

import { Component, mount, xml, whenReady } from '@odoo/owl';
import { templates } from '@web/core/assets';

export class OwlMainComponent extends Component {}

OwlMainComponent.template = 'my_folder.owl_main_component';

// VERSION 1: await template loading inside whenReady
whenReady(async () => {
	await templates;
	const element = document.getElementById('hello-box-root');
	if (element) {
		mount(OwlMainComponent, element);
	} else {
		console.warn('❌ Missing #hello-box-root');
	}
});

// VERSION 2: naive sync mount
// const element = document.getElementById('hello-box-root');
// mount(OwlMainComponent, element);

// VERSION 3: basic whenReady
// whenReady(() => {
// 	const element = document.getElementById('hello-box-root');
// 	if (element) {
// 		mount(OwlMainComponent, element, { templates });
// 	}
// });

🔍 Investigation So Far

When I intentionally break the XML file (e.g. by removing a <t>), Odoo correctly throws an error — which proves the XML is found and parsed.

I also inspected the compiled web.assets_frontend_lazy.js. It turns out:

  • The component is mounted around line 97278
  • The XML template is only registered around line 104900

This confirms the component tries to render before the template is available.

🧪 Asset Load Order (Manifest)

To fix this, I tried forcing the load order using before and prepend:

'web.assets_frontend': [
    # ('prepend', 'my_folder/static/src/js/owl_templates.xml'),
    # ('before', 'my_folder/static/src/js/owl_component.js',
    #           'my_folder/static/src/js/owl_templates.xml'),
    ('before', 'my_folder/static/src/js/owl_templates.xml', 
               'my_folder/static/src/js/owl_component.js'),
]

However, every attempt resulted in an error saying either the XML or JS file could not be found — depending on which directive I used.

🆘 Summary

At this point I’ve tried every variation I could think of. It’s very frustrating that something as basic as loading a QWeb XML file into an OWL component doesn't work as expected.

If anyone has had success with a similar setup or knows what I might be doing wrong — I’d deeply appreciate your help 🙏

形象
D Enterprise
最佳答案

Hii

__manifest__.py

{ "name": "Custom OWL Dashboard", "version": "1.0", "depends": ["base", "web"], "assets": { "web.assets_frontend": [ "my_module/static/src/js/HelloBox.js", "my_module/static/src/js/init_owl.js", ], }, "data": [ "views/dashboard_menu.xml", ], "installable": True, "application": True, }

HelloBox.js

my_module/static/src/js/HelloBox.js

/** @odoo -module **/ import { Component, xml } from "@odoo/owl"; export class HelloBox extends Component { static template = xml` <div class="hello-box bg-light p-3 rounded shadow"> <h2 class="mb-3"><t t-esc="props.title"/></h2> <button class="btn btn-primary" t-on-click="sayHello">Click me</button> </div> `; static props = { title: { type: String }, }; sayHello() { alert("Hello from OWL!"); } }

init_owl.js

my_module/static/src/js/init_owl.js

/** @odoo -module **/ import { mount, whenReady } from "@odoo/owl"; import { HelloBox } from "./HelloBox"; whenReady(() => { const root = document.getElementById("hello-box-root"); console.log("📦 Mounting HelloBox into", root); if (root) { mount(HelloBox, { target: root, props: { title: "Hello from OWL!", }, }); } else { console.warn("⚠️ Element #hello-box-root not found."); } });

dashboard_menu.xml

my_module/views/dashboard_menu.xml


<odoo> <template id="assets_backend" inherit_id="web.assets_backend" name="OWL Dashboard Assets"> <xpath expr="." position="inside"> <link rel="stylesheet" href="/web/static/lib/bootstrap/css/bootstrap.min.css"/> </xpath> </template> <record id="action_dashboard_hello" model="ir.actions.client"> <field name="name">OWL Dashboard</field> <field name="tag">hello_dashboard</field> </record> <menuitem id="menu_owl_dashboard_root" name="OWL Dashboard" sequence="10"/> <menuitem id="menu_owl_dashboard" parent="menu_owl_dashboard_root" name="Hello" action="action_dashboard_hello"/> </odoo>

JS Controller (Frontend Mount)

You need to register your OWL component on that page. Add this file:

my_module/static/src/js/dashboard_controller.js (optional if you're using OWL directly)

If you're using the tag 'hello_dashboard', register it using a JS client action — or skip that if you're directly including the root container via another QWeb view.

i hope it is usefull

0
形象
丢弃
喜欢讨论吗?不要只阅读,加入进来!

立即创建账户,享受专属功能,与我们的精彩社区互动!

注册
相关帖文 回复 查看 活动
How to hide the title or the close (X) button from a dialogService dialog?
javascript development debug
形象
形象
2
9月 25
905
Error with rpc call
javascript development function debug
形象
形象
形象
2
7月 25
1820
Custom Cards Payment Module: POS Payment Summary Not Updating with Installments
javascript development sales project
形象
形象
2
2月 25
2193
Testing of computed field in Odoo 18 extension dev
development debug
形象
1
11月 25
399
How do I correctly create a calculated field to sum two other field values in Odoo Studio (Odoo Online)? 已解决
development debug
形象
形象
2
11月 25
439
社区
  • 教学视频
  • 文档
  • 论坛
开源
  • 下载
  • Github
  • Runbot
  • 翻译
服务
  • Odoo.sh 托管
  • 支持
  • 升级
  • 自定义开发服务
  • 教育
  • 查找会计服务
  • 寻找合作伙伴
  • 成为合作伙伴
关于我们
  • 我们的公司
  • 品牌资产
  • 联系我们
  • 招聘
  • 近期活动
  • 播客
  • 博客
  • 客户
  • 法律 • 隐私
  • 安全
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo致力于为企业管理提供高效智能的开源解决方案,是全球业内高速成长的软件服务商之一,逾七百五十万用户选择Odoo进行数字化升级。通过一系列全业务链覆盖、高度集成、简单易用的商业应用,助力企业实现信息化改革、降本增效并释放公司增长潜力。

Odoo独特的价值在于是一款非常容易使用又完全集成的应用。

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now