PhpStorm 实时模板变量默认值 - 文件目录

PhpStorm live template variable default value - directory of file

我创建了使用变量的实时模板,例如:

A::set($CATEGORY$,$MESSAGE$);

我想将变量 $CATEGORY$ 的默认值设置为目录,我使用此实时模板的文件所在的目录。 有表达式 fileName() 做的事情接近我的任务。

因此,如果我在位于 app\views\home\index.php 的文件中使用我的实时模板 - 我想获得 $CATEGORY$ - 'home' 的默认值。我该怎么做?

正如 LazyOne 所说,我已经使用 GroovyScript 完成了它。没有找到实时模板函数 groovyScript() 将输出什么值,但我的代码做我想做的。

解决方案:

String path = _editor.getVirtualFile().getPath();
Integer lastIndex = path.lastIndexOf('/');
Integer startIndex = path.substring(0,lastIndex).lastIndexOf('/')+1;
path.substring(startIndex,lastIndex);