Creating a snippet file
Code snippets are templates that make it easier to enter repeating code patterns, such as loops or conditional-statements. For more information on snippets, refer to Visual Studio’s documentation on snippets.
Snippet files in Template Designer are in JSON format. Each snippet is defined under a snippet name and has a prefix, body and description.
- The prefix defines how this snippet is selected from IntelliSense and tab completion.
- The body is the content and either a single string or an array of strings of which each element will be inserted as separate line.
- The description is the description used in the IntelliSense drop down.
- With tabstops, you can make the editor cursor move inside a snippet. Use $1, $2 to specify cursor locations. The number is the order in which tabstops will be visited, whereas $0 denotes the final cursor position. Multiple occurrences of the same tabstop are linked and updated in sync.
- Placeholders are tabstops with values, like ${1:label}, ${2:another} for placeholders. The placeholder text will be inserted and selected such that it can be easily changed.
Example Snippet
Copy
Sample snippet for placing a description of the product
{
"IfProduct": {
"prefix": "ifProduct",
"body": [
"if (InvoiceDocumentProduct.Element(\"Description\").Value != \"${1:Product}\")",
"{"
],
"description": "Does an if statement on the Product Description"
},
"if": {
"prefix": "if",
"body": [
"if (${1:condition}){",
],
"description": "Opens an if statement."
}
}