Skip to content

Commit d771390

Browse files
committed
data inheritance
1 parent 7fcf258 commit d771390

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Data inheritance
2+
3+
Vento has a parent to child data inheritance system:
4+
5+
## Child templates have access to the parent's data
6+
7+
When a template includes another template (using [include](./6.include.md) or [layout](./7.layout.md)), the children template can access to the parent data. For example:
8+
9+
```vto
10+
{{ set value = "Hello world" }}
11+
12+
{{ include "child.vto" }}
13+
```
14+
15+
The child template can access to the parent variable:
16+
17+
```vto
18+
{{ value }}
19+
```
20+
21+
This doesn't happen in reverse order. A variable declared in a child component cannot be accessed by the parent template.
22+
23+
## Parent templates can edit children variables
24+
25+
Parent templates can create or modify existing variables before rendering nested templates. For example:
26+
27+
```vto
28+
{{ set value = "Hello world" }}
29+
30+
{{ include "child.vto" { value: "Other value", foo: "bar" } }}
31+
```
32+
33+
In this example, the parent variable modifies the `value` variable and creates the `foo` variable. These changes are only available in the context of the child template (and successive nested templates).

0 commit comments

Comments
 (0)