blob: d0d25ec11422b6721706cb8f5eec5fbe0ae11975 [file] [log] [blame] [view]
Marcel van Lohuizen3e592b42019-01-11 20:31:29 +01001[TOC](Readme.md) [Prev](lists.md) [Next](instances.md)
2
3_Types ~~and~~ are Values_
4
5# Templates
6
7One of CUE's most powerful features is templates.
8A template defines a value to be unified which each field of a struct.
9
10The template's identifier (in angular brackets) is bound to name of each
11of its sibling fields and is visible within the template value
12that is unified with each of the siblings.
13
14```
15// The following struct is unified with all elements in job.
16// The name of each element is bound to Name and visible in the struct.
17job <Name>: {
18 name: Name
19 replicas: 1 | uint
20 command: string
21}
22
23job list command: "ls"
24
25job nginx: {
26 command: "nginx"
27 replicas: 2
28}
29```
30
31```
32job: {
33 list: {
34 name: "list"
35 replicas: 1
36 command: "ls"
37 }
38 nginx: {
39 name: "nginx"
40 replicas: 2
41 command: "nginx"
42 }
43}
44```