How to define PHPStorm live template variable as lowercase value of another variable?

冷暖自知 提交于 2019-12-09 15:01:25

问题


I want to make a template like something $NAME$ other $LOWNAME$ so that when I use it, I'm taken to $NAME$ input list and $LOWNAME$ is automatically filled with decapitalized value of $NAME$ I input. For example, I print "Client" to $NAME$ and the value of $LOWNAME$ is "client". Is this possible?


回答1:


If by "decapitalizing" you mean to lower case only first letter then YES, otherwise No (as there is no function for lower casing all characters).

  1. Template: something $NAME$ other $LOWNAME$
  2. Click on "Edit variables" button
  3. In "Expression" column for "LOWNAME" variable enter this: decapitalize(NAME) and tick/check "Skip if defined" box

Now when template will be expanded, and if you enter "CapitalShip" for $NAME$ variable, the $LOWNAME$ will automatically become "capitalShip"

http://www.jetbrains.com/phpstorm/webhelp/edit-template-variables-dialog.html




回答2:


To do this with file templates (without expressions) in PHPStorm you can use Java functions in combination with Apache Velocity Template Language:

#set( $name = ${NAME} )
<?php

class ${NAME} extends Model{
  protected \$table = '$name.toLowerCase()';
}


来源:https://stackoverflow.com/questions/12107505/how-to-define-phpstorm-live-template-variable-as-lowercase-value-of-another-vari

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!