Learn how to make your boilerplate templates dynamic
Once you have identified your boilerplate, you can start turning the code fragments you want into variables. This action will allow your boilerplate to become a dynamic template.
Every time you use it in a project, you can add a value according to the project information you are creating, thus having your customized code ready.
Before you begin creating your dynamic boilerplate, keep in mind that:
- You have two options: create a snippet or a scaffold.
- You can create a snippet when you want to create code fragments.
- You can group several snippets if they belong to the same category or a single snippet if you don't want to group them.
- Use scaffolds if you want to have a larger structure, as with scaffolds, you can create folders, files within which you can include code and/or add snippets with saved variables.
Here's how to create a snippet using the VSCode extension:
-
Step 1: Open the Archittect extension in VSCode.
-
Step 2: Select the Snippets tab.
-
Step 3: Click the "Create new Snippet" button.
-
Step 4: Add your code in the text editor.
-
Step 5: You can add more than one snippet by clicking the plus button.
-
Step 6: Search in VSCode for the file where you want to add your snippet, go to the section of your code where you want to add it, right-click, and select the "Insert Snippet" option. Later, we will show you how to add a snippet within a scaffold.
Here's how to create a Scaffold:
- Step 1: Open the Archittect extension in VSCode.
- Step 2: Select the Scaffold tab.
- Step 3: Click the "Create new scaffold" button.
- Step 4: Start creating your structure from nodes; a node can be a folder (if you are going to add a file inside) or a file (if you are going to add content inside).
- Step 5: From now on, you can put variables in the names of your folders or files and add a transformer to them.
- Step 6: If you want to add content to a file, you must select the corresponding node, go to the node menu, and click the "Edit Content" button; a text editor will open.
- Step 7: Add your code or snippets to the file that you have saved previously.
Remember that every time you make a change, you must save it.
To insert a Snippet into a Scaffold, follow these steps:
- Step 1: Once you have created the Snippet, enter the node where you want to insert it.
- Step 2: In the menu on your right, you can see a list of Snippet groups that you have saved.
- Step 3: Expand the group you want and position your cursor where you want to insert your Snippet and click.
- Step 4: Done, you have inserted your snippet.
There is another way you can create Snippets and Scaffolds from a created project; this functionality can only be used if you are using our tool in VSCode.
Here's how to create a snippet from your code files:
- Step 1: Go to a file where you have the content you want to transform into a snippet.
- Step 2: Select the code snippet, right-click, and from the dropdown menu, select the option: "Create snippet from selection."
- Step 3: Done, you have your snippet to customize as you wish and use it whenever you want.
Here's how to create a scaffold from a file structure in VSCode:
- Step 1: Go to the folder or file you want to transform into a scaffold.
- Step 2: Right-click on the folder or file, and from the dropdown menu, choose the option: "Create scaffold from files."
- Step 3: You will see your Scaffold created within the Archittect screen.