How to use Live Templates functions in File Templates?
Answered
Hi!
Is it possible to use Live Templates functions such as capitalizeAndUnderscore and similar in File Templates with "Enable Live Templates" on?
I can't figure out what syntax should I use, none is working:
const React = require('react');
const CN_#[[capitalizeAndUnderscore($NAME)]]# = '#[[decapitalize($NAME)]]#';
export default class $NAME extends React.Component {
render() {
return (
<section className={`${this.props.className} #{CN_#[[capitalizeAndUnderscore($NAME)]]#}`}>
#[[$END$]]#
</section>
);
}
}
Thanks
Please sign in to leave a comment.
No, it's not possible to use Live Template functions there.
But File Templates use Apache Velocity template language (http://velocity.apache.org/), so you can use standard java String functions there - see http://stackoverflow.com/questions/6998412/velocity-string-function, for example. Like:
#set( $regex = "([a-z])([A-Z]+)")
#set( $replacement = "$1_$2")
#set( $toSnake = $NAME.replaceAll($regex, $replacement).toUpperCase())
#set( $toLower = $NAME.toLowerCase())
const React = require('react');
const CN_$toSnake = '$toLower';
export default class $NAME extends React.Component {
render() {
return (
<section className={`${this.props.className} #{CN_$toSnake}`}>
#[[$END$]]#
</section>
);
}
}
Thanks! This solves the problem
Hi!
https://www.jetbrains.com/help/phpstorm/2016.3/file-and-code-templates-2.html#live_template
I can use only predefined (END and SELECTION) variables?
Still can't use the live template functions?
How can I include seconds of time in my file template?
Thanks
Related issues:
https://youtrack.jetbrains.com/issue/IDEA-159930
https://youtrack.jetbrains.com/issue/IDEA-161937
Thank you!