Skip to content

Commit e3bd2c5

Browse files
authored
Merge pull request aspnetzero#310 from aspnetzero/pr/5329
Update How-To-Create-Edit-Power-Tools-Templates.md
2 parents 5fd4f8a + be93116 commit e3bd2c5

File tree

1 file changed

+63
-3
lines changed

1 file changed

+63
-3
lines changed

docs/en/How-To-Create-Edit-Power-Tools-Templates.md

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,70 @@ If you want to edit any file, copy it in the same directory and change it's an e
1818

1919
## Create New Templates
2020

21-
To create new templates, simply add a new file to the `FileTemplates` directory. You can use the existing templates as a reference. For guidance on how templates function and how to use placeholders, please refer to the documentation provided at [Understanding Power Tools Templates](power-tools-understanding-power-tools-templates.md).
21+
Choose a folder under the `FileTemplates` directory based on where the file you're creating in your project will reside (e.g., `Server`, `Client` -> `Mvc` or `Angular`, `Test`). Then, create a folder named after the file you’re creating. Inside this folder, create the following three files: `MainTemplate.txt`, `PartialTemplates.txt`, and `TemplateInfo.txt`.
22+
23+
You can use the existing templates as a reference. For guidance on how templates function and how to use placeholders, please refer to the documentation provided at [Understanding Power Tools Templates](power-tools-understanding-power-tools-templates.md).
2224

2325
Power Tools discovers templates in the `FileTemplates` directory every time it is run. So, restarting Power Tools will find your newly created templates.
2426

25-
## Change Destination Path Of New Files
27+
### Example Custom Template
28+
29+
Let's say you want to create a new template for generating a new class in the `*.Core.Shared` project. It is an entity constant class that contains some constant values. Here is how you can create a new template for this:
30+
31+
1. Create a new folder named `CustomTemplate` under `AspNetZeroRadTool/FileTemplates/Server` directory.
32+
> Hint: You can use a prefix like ANZ to group your templates. For example, `ANZ_CustomTemplate`. Or refoldering, for example `FileTemplates\Server\MyTemplates\ANZ_CustomTemplate` This will help you to find your templates easily.
33+
34+
2. Create `MainTemplate.txt`, `PartialTemplates.txt`, and `TemplateInfo.txt` files inside the `ConstantClass` folder.
35+
36+
**MainTemplate.txt**
37+
38+
```txt
39+
{{Enum_Using_Looped_Template_Here}}
40+
using System;
41+
42+
namespace {{Namespace_Here}}.{{Namespace_Relative_Full_Here}}
43+
{
44+
public static class {{Entity_Name_Here}}CustomConsts
45+
{
46+
{{Property_Looped_Template_Here}}
47+
}
48+
}
49+
```
50+
51+
**PartialTemplates.txt**
52+
53+
```txt
54+
{
55+
"propertyTemplates":[
56+
{
57+
"placeholder" : "{{Property_Looped_Template_Here}}",
58+
"condition" : "",
59+
"templates" : [
60+
{
61+
"type" : "default",
62+
"content" : "public static readonly string {{Property_Name_Here}} = \"{{Property_Name_Here}}\";
63+
"
64+
},
65+
]
66+
}
67+
],
68+
"navigationPropertyTemplates":[
69+
],
70+
"enumTemplates":[
71+
{
72+
"placeholder" : "{{Enum_Using_Looped_Template_Here}}",
73+
"preventDuplicate":true,
74+
"content" : "using {{Enum_Namespace_Here}};"
75+
}
76+
],
77+
}
78+
```
79+
80+
**TemplateInfo.txt**
2681

27-
To change the destination path of a template, find the template folder of it in `AspNetZeroRadTool/FileTemplates` directory and edit the content of `TemplateInfo.txt` file.
82+
```txt
83+
{
84+
"path" : "{{Namespace_Here}}.Core.Shared\\{{Namespace_Relative_Full_Reverse_Slash_Here}}\\{{Entity_Name_Here}}CustomConsts.cs",
85+
"condition": "{{Is_Master_Detail_Page_Child_Here}} == false",
86+
}
87+
```

0 commit comments

Comments
 (0)