mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[IMP] component tags: allow injecting values in xml tag string
With this commit, we can now do this:
const SUBTEMPLATE = xml`<span><t t-esc="state.n"/></span>`
class Parent extends Widget {
static template = xml`<div><t t-call="${SUBTEMPLATE}"/></div>`
state = {n: 42};
}
This commit is contained in:
@@ -1068,6 +1068,24 @@ exports[`other directives with t-component t-on with stop and/or prevent modifie
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`random stuff/miscellaneous can inject values in tagged templates 1`] = `
|
||||
"function anonymous(context,extra
|
||||
) {
|
||||
var h = this.h;
|
||||
let c1 = [], p1 = {key:1};
|
||||
var vn1 = h('div', p1, c1);
|
||||
result = vn1;
|
||||
let c2 = [], p2 = {key:2};
|
||||
var vn2 = h('span', p2, c2);
|
||||
c1.push(vn2);
|
||||
var _3 = context['state'].n;
|
||||
if (_3 || _3 === 0) {
|
||||
c2.push({text: _3});
|
||||
}
|
||||
return vn1;
|
||||
}"
|
||||
`;
|
||||
|
||||
exports[`random stuff/miscellaneous snapshotting compiled code 1`] = `
|
||||
"function anonymous(context,extra
|
||||
) {
|
||||
|
||||
@@ -2310,6 +2310,19 @@ describe("random stuff/miscellaneous", () => {
|
||||
"C:patched"
|
||||
]);
|
||||
});
|
||||
|
||||
test("can inject values in tagged templates", async () => {
|
||||
const SUBTEMPLATE = xml`<span><t t-esc="state.n"/></span>`
|
||||
class Parent extends Widget {
|
||||
static template = xml`<div><t t-call="${SUBTEMPLATE}"/></div>`
|
||||
state = {n: 42};
|
||||
}
|
||||
|
||||
const widget = new Parent(env);
|
||||
await widget.mount(fixture);
|
||||
expect(env.qweb.templates[Parent.template].fn.toString()).toMatchSnapshot();
|
||||
expect(fixture.innerHTML).toBe('<div><span>42</span></div>')
|
||||
});
|
||||
});
|
||||
|
||||
describe("async rendering", () => {
|
||||
|
||||
Reference in New Issue
Block a user