Anood
Anood

Reputation: 13

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.

Upvotes: 1

Views: 1498

Answers (1)

bgerth
bgerth

Reputation: 1286

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.

Upvotes: 1

Related Questions