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

前端 未结 2 578
谎友^
谎友^ 2021-02-13 17:17

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 de

相关标签:
2条回答
  • 2021-02-13 17:43

    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()';
    }
    
    0 讨论(0)
  • 2021-02-13 17:44

    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

    0 讨论(0)
提交回复
热议问题