是否可以将实时模板用作文件模板? [英] Is it possible to use live-templates as file templates?
问题描述
在intellij产品中,我非常喜欢实时模板。我想知道是否可以对文件模板使用相同的语法,例如将变量格式化为snake-或camel-camese,定义起始光标位置等等。
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.
推荐答案
不幸的是你不能使用文件模板中的实时模板中可用的相同功能/宏。
文件模板使用 Apache Velocity模板语言。它允许在变量上运行一些Java(?)简单方法(例如 #set($ class_start = $ class.substring(0,1).toUpperCase())
) 。很可能更复杂的方法也可以。
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.
更新(2017/01/13):
从 2016.1 (或可能是2016.2)版本开始,现在可以在文件模板中使用一些实时模板(通过检查该文件模板的启用实时模板
复选框)。我不是100%肯定它是否会在这里做请求(没有自己测试)。
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).
语法示例:#[$ MY_VARIABLE $ $ END $]]
https://www.jetbrains.com/help/phpstorm/2016.3/file-and-code-templates-2.html
这篇关于是否可以将实时模板用作文件模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!