views:

129

answers:

1

I like the idea of creating file templates for common functionality - for example having a controller template that gives you a subbed out controller.

What i am looking for is the ability to do some scripting in the template, for example i can have the controller name be input by the user: ${CONTROLLER_NAME}

but then later i might want to use that name as a field, but i cannot because it usually begins with an upper case letter, and i would need to lower case the first letter to use it. I havent found a way to do that in the templates.

I heard these templates are actually velocity templates, so maybe some scripting is possible? (i dont know velocity)

+2  A: 

Apache Velocity Templates is a powerful thing and can indeed help you with this task.

In the beginning of your 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 controller name with the first letter in lower case.

I've verified it with the user name in the common file header template and it worked well: File Template with lower case first letter of the user name

CrazyCoder