Is it possible to use live-templates as file templ

2019-05-06 07:40发布

In the intellij products I'm very fond of the live-templates. I wonder if it is possible to use the same syntax for file templates, e.g. formatting a variable to snake- or camel-camese, defining a starting cursor position and so on.

1条回答
The star\"
2楼-- · 2019-05-06 08:23

Unfortunately you cannot use the same functions/macros available in Live Templates in File Templates.

File Templates use Apache Velocity template language. It allows some Java(?) simple methods to be run on variables (e.g. #set($class_start = $class.substring(0,1).toUpperCase())). Quite possible that more complex methods will work as well.


UPDATE (2017/01/13):

As of 2016.1 (or perhaps 2016.2) version it's now possible to use some Live Templates in File Templates as well (by checking Enable Live Templates checkbox for that File template). I'm not 100% sure if it will do the requested here thing (not tested myself).

Syntax example: #[[ $MY_VARIABLE$ $END$ ]]#

https://www.jetbrains.com/help/phpstorm/2016.3/file-and-code-templates-2.html

查看更多
登录 后发表回答