1

When creating a live template in WebStorm 2017.3.2 is there a way to apply multiple predefined functions on a single input? Or perhaps reference template variables from other template variables from within the same template?

Say for example I want to apply the capitalizeAndUnderscore function to $FOO$ and also apply the camelCase function to the same input supplied to the $FOO$ variable elsewhere in the template?

In other words, is it possible to achieve the following:

$FOO$: '$FOO_REFERENCE$' expands to MY_WHATEVER: 'myWhatever'

While only having to type mywhatever 1 single time?

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Ryder Brooks
  • 2,049
  • 2
  • 21
  • 29
  • 2
    Have a look at these answers in case if you still need some clarifications (on what @lena said/how it works): https://stackoverflow.com/a/12108117/783119 ; https://stackoverflow.com/a/38523228/783119 ; https://stackoverflow.com/a/41634968/783119 – LazyOne Mar 07 '18 at 09:36

1 Answers1

3

Both capitalizeAndUnderscore() and camelCase() functions have String parameter - it can be a string constant, expression or a reference to already defined variable. So, you can easily use capitalizeAndUnderscore(FOO) as $FOO_REFERENCE$ value. But referencing variables defined in other templates is not supported. And you need to make sure that $FOO$ value is defined before being used.

lena
  • 90,154
  • 11
  • 145
  • 150
  • I'm reading this to mean that the predefined functions can be called from within the live template and don't have to be used strictly through the variables dialog where all the clicky stuff is. Am I understanding you correctly? – Ryder Brooks Mar 06 '18 at 18:22
  • 1
    no, nothing of the kind; functions can only be used as variable expressions in **edit template variables** dilaog, you can't use them directly in template code – lena Mar 06 '18 at 19:34
  • BTW, we are working on re-designing **template variables** dialog to make it more user-friendly; please follow https://youtrack.jetbrains.com/issue/IDEA-146698 for updates – lena Mar 07 '18 at 12:36