mirror of
https://github.com/odoo/owl.git
synced 2025-10-06 19:59:41 +07:00
[FIX] qweb: correctly handle top level t-call and body
Whenever a top level t-call was made with some non empty body, Owl complained that a template should not have more than one root node. The reason was that the compilation context for the body of the t-call directive was the same as the root compilation context, and it already had a parentNode set. To fix the issue, this commit simply use the subContext method to create a different compilation context, which actually makes sense, because the body of a t-call is really a different situation. Also, as a bonus, it slightly improves the code for the t-call directive. closes #760
This commit is contained in:
@@ -267,16 +267,13 @@ QWeb.addDirective({
|
||||
for (let attr of ["t-if", "t-else", "t-elif", "t-call"]) {
|
||||
nodeCopy.removeAttribute(attr);
|
||||
}
|
||||
const parentNode = ctx.parentNode;
|
||||
ctx.parentNode = "__0";
|
||||
// this local scope is intended to trap c__0
|
||||
ctx.addLine(`{`);
|
||||
ctx.indent();
|
||||
ctx.addLine("let c__0 = [];");
|
||||
qweb._compileNode(nodeCopy, ctx);
|
||||
qweb._compileNode(nodeCopy, ctx.subContext("parentNode", "__0"));
|
||||
ctx.rootContext.shouldDefineUtils = true;
|
||||
ctx.addLine("scope[utils.zero] = c__0;");
|
||||
ctx.parentNode = parentNode;
|
||||
ctx.dedent();
|
||||
ctx.addLine(`}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user