Search code examples
templateswebstormvelocityjetbrains-ide

How to get filename without extension in Apache Velocity template lang?


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.


Solution

  • 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.