![]() ![]() Use them consistently and you will have documented code. 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: By Alexey Filatov Train Yourself with Keyboard Shortcuts The IdeaVim plugin Advanced Search Live Templates Usage for All Basic Language Structures Avoid. 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. With the PHP heading highlighted in the Live Templates settings, click on the green +. There are a different set of groups, each group has it's own set of Live Templates. In the area at the bottom, give your template an abbreviation name: vdd. 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. This is about the process, rather than the code.Documenting your code is always a hassle and usually left till the end. It's not so important to understand what this code does, so if you are unsure then don't worry about it. If you have ever worked with Symfony's Form Collection then you will likely have had to type this out at least once. This example comes directly from the video. This frees up valuable brain space, allowing me to remember more important things like old Simpsons' quotes (true), and relatives birthdays (no true). ![]() I'm particularly bad at remembering how to correctly define a Symfony controller from scratch, or the exact syntax and layout for a Symfony Form Type.įor these, I use custom live templates. Read some docs / blog post / StackOverflow article, copy the interesting bits, paste into your code and see if it works. If you work like I do, copy/paste is a common occurrence. Live Templates are the secret sauce to increasing your development productivity inside PHPStorm. What you may not know is that you are not only limited to the code generators that PHPStorm comes with out of the box. The code generation feature is particularly useful. How to customise your Getter / Setter templates in PHPStorm ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |