accordproject / template-archive

Smart Legal Contracts & Templating System
https://accordproject.org/projects/cicero/
Apache License 2.0
280 stars 119 forks source link

Variables within #optional body are reported as unknown #680

Open norweis opened 3 years ago

norweis commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

norweis commented 3 years ago

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 commented 3 years ago

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