I am building a template using the dotnet new template engine.
I have a parameter that looks like this:
"symbols": {
"rootEntity": {
"displayName": "Root Entity",
"type": "parameter",
"datatype": "string",
"replaces": "Notebook",
"defultName": "Notebook",
"isRequired": false,
"description": "An example root level data entity"
},
... other parameters here
}
It seems to mostly work, but it only replaces Notebook, not notebook. I could add another parameter for the lowercase version, but that requires users to type it in twice (yuck).
I saw the casing generator, but it does all uppercase or all lowercase (not just the first letter).
Digging more, I found a thing called a form that has the options firstLowerCase and firstUpperCase. But I can't find any examples using forms, only symbols (as shown in my example).
So, I have two possible questions (either will work):
- How can I lowercase or uppercase the first letter of a symbol variable
- How can I use
formsin a template.
(I would prefer the second question as that enables me to use all the forms, but the first will get me moving forward, so I would be happy with either.)
About forms
To use a form, it must be declared in the
formssection, on the same level as thesymbolssection. After that, the form can be used where it is expected, for example, in thederivedparameters. In the example below, there is a parameterUserName, and a transformativederivedparameter that transforms the value ofUserNameto lowercase:Lowercase first letter of a parameter
So, you have such a template.json file:
And you want to have a source file with the following code:
And after executing the command
dotnet new mt --RootEntity "Hello world"you need a file with the following contents (as far as I understand):I suggest you use the
derivedparameter and an empty form:In the
formssection, thenotTransformform is declared. This form does nothing - it is empty.rootEntityLowerCaseis aderivedparameter that takes the value of therootEntityparameter and applies to it the transformation specified by thenotTransformform (this form does nothing :)). The value of therootEntityLowerCaseparameter is inserted wherever thenotebooktext occurs.