
If your template name is long, you can specify what letters to use to select it.
#Webstorm live edit code#
Surround is used when you have selected code that you want to surround, like adding a try/catch. Generation means the creation of new code. This is helpful to explain what the template does for others This also appears in the Intellisense listsĪ description of the template. This is what you type in the editor to use this snippet. This is where you can tweak the settings a bit Name Now, I can expand this a little bit more with some ‘smarts’ from the IDE by adding live template functions but that maybe another blog posts. For my unit test, the first variable is MethodName, which is the method I am testing, followed by What the tests expect as input, then followed up with the test should DoWhat, and the template Ends in a position where I can start arranging the tests. They should reference what they are doing or expecting. The names matter as much as naming your methods or variables in code. The $END$ indicates where the editing caret should end when you are complete with editing all the variables. So, in Rider/Visual Studio, when I enable the template, I will be prompted inline for the $MethodName$, then $What$, then $DoWhat$. In this example, I have 4, $MethodName$, $What$, $DoWhat$, and $END$. The dollar signs are used for variables/inputs/prompts for your template. What are those dollar signs ( $) for you ask? Well, I am glad you asked. Use them consistently and you will have documented code.Public void MethodName_WithSomething_ShouldDoSomething () To make life easier, there are DocBlocks for the file, class, variable, and methods aptly named fblock (file block), cblock (class block), vblock (variable block) and mblock (method block). Whenever a class is created I first use the cblock Live Template, it is an easy way not to forget to add a DocBlock. As the animation shows, this is a Live Template that creates a DocBlock for a class. Now that we know we can use Live Templates, we can use them to document code. Hitting Enter or Tab will use the first option in the suggestion list.ĭocumenting your code using Live Templates Once the Live Template is in the suggestion list you can either click it, Enter or Tab to replace the abbreviation with the defined template text. As you type, PhpStorm will suggest possible commands including the live templates. To use a Live Template all that needs to be done is start typing the abbreviation set for the Live Template. You can further customize the variables by clicking the Edit variables button. Variables can have any name you like but must always be enclosed within $ signs. PhpStorm tabs through the variables from top to bottom. These variables allow you to fill these with actual values after the Live Template has been activated. Any text can be put in here but to make it even more useful you can use variables. The template text is the actual text that is pasted into your file when you activate the Live Template. Clicking on the Change button will show you a list where you can select in which language the Live Template is available.

The Live Template from the screenshot is only available in a PHP file. This sets in which context the Live Template should be available. This is the area where you setup the actual text that is inserted when you trigger the Live Template. This is the abbreviation you will use to trigger the Live TemplateĪ description that explains what the Live Template does There are several fields to fill out here: A new Live Template is created and you can now configure the Live Template. To create a Live Template click on the + sign in the right toolbar and you are asked if you want to create a new Live Template or a Template Group. The group is only there for organizing it doesn't influence how the Live Template is used. All others are grouped by the type of Live Template. The groups make it easier to organize the Live Templates, in the image you can see there is also a group called RolandD, that is my own group.

There are a different set of groups, each group has it's own set of Live Templates. This will bring you to this screen and you will notice that PhpStorm comes with a bunch of Live Templates out of the box. Live templates can be configured by going to Preferences -> Editor -> Live Templates. These variables can be filled in on the fly. A live template is a code snippet with variables. Live templates are a feature in PhpStorm that has many uses, not just for documenting your code. Once you figured it out you realize there is no time to document it now since you lost all that time figuring out what it was for and you need to move on. The end meaning never and when you need that code again you spend all that time figuring out what the function was for. Documenting your code is always a hassle and usually left till the end.
