[DOC] add some information on variables and t-call

closes #540
This commit is contained in:
Géry Debongnie
2019-12-05 21:45:47 +01:00
parent ecfccf2448
commit f5b3ef5cf3
4 changed files with 24 additions and 16 deletions
@@ -500,6 +500,15 @@ will result in :
</div> </div>
``` ```
This can be used to define variables scoped to a sub template:
```xml
<t t-call="other-template">
<t t-set="var" t-value="1"/>
</t>
<!-- "var" does not exist here -->
```
### Translations ### Translations
By default, QWeb specify that templates should be translated. If this behaviour By default, QWeb specify that templates should be translated. If this behaviour
+1 -2
View File
@@ -137,8 +137,7 @@ export class Portal extends Component<any, any> {
} }
this.__checkVNodeStructure(vnode); this.__checkVNodeStructure(vnode);
const shouldDeploy = const shouldDeploy =
(!this.portal || this.el!.contains(this.portal.elm!)) && (!this.portal || this.el!.contains(this.portal.elm!)) && !this.doTargetLookUp;
!this.doTargetLookUp;
if (!this.doTargetLookUp && !shouldDeploy) { if (!this.doTargetLookUp && !shouldDeploy) {
// Only on pure patching, provided the // Only on pure patching, provided the
+1 -1
View File
@@ -650,7 +650,7 @@ export class QWeb extends EventBus {
if (!name.startsWith("t-") && !(<Element>node).getAttribute("t-attf-" + name)) { if (!name.startsWith("t-") && !(<Element>node).getAttribute("t-attf-" + name)) {
const attID = ctx.generateID(); const attID = ctx.generateID();
if (name === "class") { if (name === "class") {
if (value = value.trim()) { if ((value = value.trim())) {
let classDef = value let classDef = value
.split(/\s+/) .split(/\s+/)
.map(a => `'${a}':true`) .map(a => `'${a}':true`)
+13 -13
View File
@@ -563,16 +563,16 @@ describe("Portal: Basic use and DOM placement", () => {
const parent = new Parent(); const parent = new Parent();
await parent.mount(fixture); await parent.mount(fixture);
expect(outside.innerHTML).toBe('<span>gloria</span>'); expect(outside.innerHTML).toBe("<span>gloria</span>");
expect(parent.el!.innerHTML).toBe('<portal></portal>'); expect(parent.el!.innerHTML).toBe("<portal></portal>");
parent.unmount(); parent.unmount();
expect(outside.innerHTML).toBe(''); expect(outside.innerHTML).toBe("");
expect(parent.el!.innerHTML).toBe('<portal><span>gloria</span></portal>'); expect(parent.el!.innerHTML).toBe("<portal><span>gloria</span></portal>");
await parent.mount(fixture); await parent.mount(fixture);
expect(outside.innerHTML).toBe('<span>gloria</span>'); expect(outside.innerHTML).toBe("<span>gloria</span>");
expect(parent.el!.innerHTML).toBe('<portal></portal>'); expect(parent.el!.innerHTML).toBe("<portal></portal>");
}); });
test("portal manual unmount with subcomponent", async () => { test("portal manual unmount with subcomponent", async () => {
@@ -587,7 +587,7 @@ describe("Portal: Basic use and DOM placement", () => {
} }
} }
class Parent extends Component<any, any> { class Parent extends Component<any, any> {
static components = { Portal , Child }; static components = { Portal, Child };
static template = xml` static template = xml`
<div> <div>
<Portal target="'#outside'"> <Portal target="'#outside'">
@@ -599,16 +599,16 @@ describe("Portal: Basic use and DOM placement", () => {
const parent = new Parent(); const parent = new Parent();
await parent.mount(fixture); await parent.mount(fixture);
expect(outside.innerHTML).toBe('<span>gloria</span>'); expect(outside.innerHTML).toBe("<span>gloria</span>");
expect(parent.el!.innerHTML).toBe('<portal></portal>'); expect(parent.el!.innerHTML).toBe("<portal></portal>");
parent.unmount(); parent.unmount();
expect(outside.innerHTML).toBe(''); expect(outside.innerHTML).toBe("");
expect(parent.el!.innerHTML).toBe('<portal><span>gloria</span></portal>'); expect(parent.el!.innerHTML).toBe("<portal><span>gloria</span></portal>");
await parent.mount(fixture); await parent.mount(fixture);
expect(outside.innerHTML).toBe('<span>gloria</span>'); expect(outside.innerHTML).toBe("<span>gloria</span>");
expect(parent.el!.innerHTML).toBe('<portal></portal>'); expect(parent.el!.innerHTML).toBe("<portal></portal>");
}); });
}); });