-
Can there be multiple inputs to a template? // All contexts collected under top-level "contexts:" key
contexts: [Name=_]: #Context & {
name: Name
password: Name
favorite_color: #DefaultColor
} In this template I can provide "Name" like so: contexts: context_one: {}
contexts: context_two: {} Is there some way to provide another "parameter" to the template? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
"Templates" have gone through a few names and have also been called "Bulk Optional Fields" and "Pattern Constraints." I believe Pattern Constraints is the correct usage now. (and tour/types/templates/ needs to be updated. See the paragraph before the 3rd code block here: https://cuelang.org/docs/references/spec/#structs In this sense, you are matching field labels and providing constraints. There are a couple of things you do. 1. Provided more labels and matching context: [Role=_]: [Name=_]: & {
name: Name
role: Role
foo: "bar"
}
context: {
admin: {
bob: _
mary: _
}
user: {
darth: _
sue: _
}
} This implies nesting your values of interest under more fields. 2. Use the function pattern #MakeUser: {
Name: string
Role: string
Result: {
name: Name
role: Role
foo: "bar"
}
}
user: (#MakeUser & { Name: "bob", Role: "user" }).Result You could loop over a list of "inputs" and generate the more complete data this way |
Beta Was this translation helpful? Give feedback.
"Templates" have gone through a few names and have also been called "Bulk Optional Fields" and "Pattern Constraints." I believe Pattern Constraints is the correct usage now. (and tour/types/templates/ needs to be updated. See the paragraph before the 3rd code block here: https://cuelang.org/docs/references/spec/#structs
In this sense, you are matching field labels and providing constraints. There are a couple of things you do.
1. Provided more labels and matching
This implies nesting your values of interest under more fields.
2…