Skip to content

Multiple inputs to a template (e.g. a "pattern constraint") #1321

Answered by verdverm
dontlaugh asked this question in Q&A
Discussion options

You must be logged in to vote

"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…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dontlaugh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants