PhpStorm 实时模板变量默认值 - 文件目录 [英] PhpStorm live template variable default value - directory of file

查看:186
本文介绍了PhpStorm 实时模板变量默认值 - 文件目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've created live template that uses variables, something like :

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

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

And I want to set default value of variable $CATEGORY$ as a directory, where the file I've used this live template located. There is expression fileName() that does a thing close to my task.

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

So if I use my live template in file located app\views\home\index.php - I would like to get default value for $CATEGORY$ - 'home'. How can I do this?

推荐答案

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

I've made it using GroovyScript as LazyOne says. Didn't found what value live template function groovyScript() will output, but my code doing what i wanted.

解决方案:

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

这篇关于PhpStorm 实时模板变量默认值 - 文件目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆