0

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?

1

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

I have followed the references from LazyOne's answer, but if I wanted to make a script which I call by file name, how do I pass the filePath() as a parameter and receive it in the script? I assume I would call the script with groovyScript("~/my_file", filePath())

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.