About forms
To use a form, it must be declared in the forms
section, on the same level as the symbols
section. After that, the form can be used where it is expected, for example, in the derived
parameters. In the example below, there is a parameter UserName
, and a transformative derived
parameter that transforms the value of UserName
to lowercase:
{
"author": "Author",
"name": "My template",
"identity": "My.Template.Boo",
"shortName": "mt",
"symbols": {
"UserName": {
"displayName": "User name",
"type": "parameter",
"datatype": "string",
"replaces": "UserName"
},
"UserNameLowerCase": {
"type": "derived",
"valueSource": "UserName",
"valueTransform": "lowerCaseForm",
"replaces": "username"
}
},
"forms": {
"lowerCaseForm": {
"identifier": "lowerCase"
}
}
}
Lowercase first letter of a parameter
So, you have such a template.json file:
{
"author": "Author",
"name": "My template",
"identity": "My.Template.Boo",
"shortName": "mt",
"symbols": {
"rootEntity": { // parameter from command line
"displayName": "Root Entity",
"type": "parameter",
"datatype": "string",
"replaces": "Notebook",
"defultName": "Notebook",
"isRequired": false,
"description": "An example root level data entity"
}
}
}
And you want to have a source file with the following code:
Upper: Notebook
lower: notebook
And after executing the command dotnet new mt --RootEntity "Hello world"
you need a file with the following contents (as far as I understand):
Upper: Hello world
lower: Hello world
I suggest you use the derived
parameter and an empty form:
{
"author": "Author",
"name": "My template",
"identity": "My.Template.Boo",
"shortName": "mt",
"symbols": {
"rootEntity": {
"displayName": "Root Entity",
"type": "parameter",
"datatype": "string",
"replaces": "Notebook",
"defultName": "Notebook",
"isRequired": false,
"description": "An example root level data entity"
},
"rootEntityLowerCase": {
"type": "derived",
"valueSource": "rootEntity",
"valueTransform": "notTransform",
"replaces": "notebook"
}
},
"forms": {
"notTransform":{
}
}
}
In the forms
section, the notTransform
form is declared. This form does nothing - it is empty. rootEntityLowerCase
is a derived
parameter that takes the value of the rootEntity
parameter and applies to it the transformation specified by the notTransform
form (this form does nothing :)). The value of the rootEntityLowerCase
parameter is inserted wherever the notebook
text occurs.