Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variables within #optional body are reported as unknown #680

Open
norweis opened this issue Jul 15, 2021 · 5 comments
Open

Variables within #optional body are reported as unknown #680

norweis opened this issue Jul 15, 2021 · 5 comments

Comments

@norweis
Copy link

norweis commented Jul 15, 2021

In the Contract Grammar field, variables within #optional body are reported as unknown. E.g. (with "String name optional" in a model), the following reports: "Unknown property: name File text/grammar.tem.md line -1 column -1":

  {{#optional name}} Name: {{name}} {{/optional}}

No variables are evaluated within the #optional Body.

Expected Behavior

In https://docs.accordproject.org/docs/markup-templatemark.html#optional-blocks a similar sample is used, but it does not work. Expected behavior is that if name is set in ContractData to value x, then Name: x should be displayed.

Current Behavior

False error message: "Unknown property: name File text/grammar.tem.md line -1 column -1".
It also contains wrong line and column.

Steps to Reproduce

  1. Use e.g. standard Hello world model which opens on start of Accord Studio
  2. Make model variable "name" optional
  3. Add to the grammar, e.g. as a last line: {{#optional name}} Name: {{name}} {{/optional}}

Context (Environment)

It occurs in any context (Browser, OS, ...) in latest Accord Studio.

@norweis
Copy link
Author

norweis commented Jul 15, 2021

The background for this is that I am currently evaluating the use of Accord for International Data Spaces IDS Data Usage Contracts, see https://internationaldataspaces.org/.
Such a contract has many clauses which are activated by contract model variables when set, and the value of such a variable should be displayed within the the text for that clause.

@jeromesimeon
Copy link
Member

Hi @norweis,

When you write an optional block:

{{#optional name}} Name: {{name}} {{/optional}}

This changes what variables are in scope for the content of that block:

// here `name` is in scope
{{#optional name}} /* here the _content_ of `name` is in scope /* {{/optional}}

So in the case where name is an atomic type you can use the special variable {{this}} which should contain the name:

{{#optional name}} Name: {{this}} {{/optional}}

For a complex type though you would most likely write something like this:

{{#optional name}} Name: {{firstName}} {{lastName}} {{/optional}}

Assuming name is something like:

concept Person {
 ...
 o Name name
 ...
}

concept Name {
  o String firstName
  o String lastName
}

@norweis
Copy link
Author

norweis commented Jul 15, 2021

Thank you. It works. But it is not documented.

@norweis
Copy link
Author

norweis commented Jul 15, 2021

A small error remains: Unknown property: name File text/grammar.tem.md line -1 column -1":
It should report the correct line, column of the occurence of name, and possibly the hint : do you mean {{this}}

@jeromesimeon
Copy link
Member

This issue isn't about template studio. Moving it to Cicero, more relevant.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants