user8620109
user8620109

Reputation: 23

PhpStorm live template variable default value - directory of file

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

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

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.

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?

Upvotes: 0

Views: 558

Answers (1)

user8620109
user8620109

Reputation: 23

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.

Solution:

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

Upvotes: 1

Related Questions