Intellij file templates - is scripting possible?

I like the idea of ​​creating file templates for general functionality - for example, with a controller template that gives you a subtitle controller.

What I'm looking for is the ability to make some scripts in a template, for example, I can enter the name of the controller by the user: $ {CONTROLLER_NAME}

but later I could use this name as a field, but I cannot, because it usually starts with an uppercase letter, and I will need to use lowercase for the first letter. I did not find a way to do this in templates.

I heard that these patterns are actually speed patterns, so maybe some scenarios are possible? (I don't know the speed)

+6
intellij-idea templates
source share
1 answer

Apache speed templates are a powerful thing and can really help you in this task.

At the beginning of the file template, put the following:

#set ($CTRL_NAME = $CONTROLLER_NAME.substring(0,1).toLowerCase() + $CONTROLLER_NAME.substring(1)) 

Later in the template, you can use ${CTRL_NAME} , which will contain the name of the controller with the first letter in lowercase.

I checked it with the username in the header template of the shared file, and it worked fine.

+18
source share

All Articles