1

In WebStorm I want to define a template like this:

<template src="./${FILE_NAME}.tmpl">
</template>
<script src="./${FILE_NAME}.js">
</script>
<style scoped src="./${FILE_NAME}.css">
</style>

And I want get the filename without extension.

And my question is can I do some string operations to the variable ${FILE_NAME} and HOW, or does it exited a variable like ${FILE_NAME_WITHOUT_EXTENSION} that I can use.

LazyOne
  • 158,824
  • 45
  • 388
  • 391
Anood
  • 13
  • 3
  • I find out use `${NAME}` works, still curious about if it supports some string operations ( e.g. , split, lowercase ) – Anood Aug 08 '20 at 05:31
  • 1
    Check this thread: https://intellij-support.jetbrains.com/hc/en-us/community/posts/360009381480-How-to-execute-functions-in-file-templates- The just look at other questions here on SO where [tag:velocity] is used (especially with JetBrains IDEs tags, e.g. [tag:jetbrains-ide] or especially [tag:intellij-idea]) – LazyOne Aug 08 '20 at 09:59
  • 1
    https://stackoverflow.com/a/6998581/783119, https://stackoverflow.com/q/40312417/783119 – LazyOne Aug 08 '20 at 10:12
  • According to my test: `${NAME}.toUpperCase()` => `tetete.toUpperCase()`, `$NAME.toUpperCase()` => `TETETE`,`${NAME.toUpperCase()}` => `TETETE`. I find out that use Formal Reference Notation(${variable}) perform differently with shorthand notation for references($variable), use ${} will ignore the char left and compiler it as string. ref: http://velocity.apache.org/engine/devel/user-guide.html#formal-reference-notation – Anood Aug 08 '20 at 17:14

1 Answers1

1

I am using

#set ( $len = $NAME.length() - 3 )
#set ( $fileName = $NAME.substring(0, $len) )

, because I know my filename ends in .js.

can I do some string operations

Yes, because it's a java.lang.String. I assume

#set ( $len = $NAME.lastIndexOf('.') - 1)
#set ( $fileName = $NAME.substring(0, $len) )

might work in your case.

bgerth
  • 1,256
  • 1
  • 12
  • 19