Timestamped Live Template “Todos” in PHPStorm

Sometimes when working on a web application we sometimes come across certain code that should be changed or we’ve half-implmented a feature and have to shift our focus on something else, and we often add a simple “// TODO: This field should be validated as an Email instead of String”-comment or something like that which gives a brief but concise explanation of what needs to be done to the code before we shift our focus to something else.

When writing these I like to put the date and my name, so that I and others on my team can get an idea of when the comment was made and who made it.

Example:

So let me walk you through the process of adding this type of comment in PHPStorm.

How to add Live Template in PHPStorm

Click on File -> Settings ( Ctrl + Alt + S)

Screenshot_1

Type live template in the search box to quickly be taken to the live template settings.

Click on the green plus icon to add a new live template

 

Screenshot_2

Write “todo” or whatever abbreviation you want to use into the Abbreviation text box.

Then write the following in the “Template text” box:  // TODO($date$) ~ Your Name:

Then click on Edit variables and write the following into the fields that appear.Screenshot_3

 

We then need to define the context (Which programming language this Live Template is available in), I use PHP and Javascript as they use the same syntax for comments.

live-template-context

 

Then click OK and Apply, we can now use this nippet in our code.

Screenshot_4

Results in:

Screenshot_5

Leave a Reply

Your email address will not be published. Required fields are marked *