IntelliJ Custom Template Variable

前端 未结 2 1952
悲哀的现实
悲哀的现实 2021-01-23 21:23

I am trying to create my custom template with a custom variable called $MyName. And I think it should be possible for IntelliJ to ask about the variable\'s value if

相关标签:
2条回答
  • 2021-01-23 21:59

    File Template Variables

    File | Settings | Editor | File and Code Templates
    You should set it in files. If set in includes, the new file is directly output variable name instead of variable content. For example, set the Java Class file Custom variable$DESCRIPTION.If the value of a variable is not defined in the template, IntelliJ IDEA will ask you to specify it when the template is applied.
    #if (${PACKAGE_NAME} && ${PACKAGE_NAME} != "")package ${PACKAGE_NAME};#end #parse("File Header.java") /** * Description: $DESCRIPTION * Created by ${USER} * Date: ${YEAR}/${MONTH}/${DAY} * Time: ${TIME} */ public class ${NAME} { }

    you can also define the values of custom variables right in the template using the #set directive. For example, if you want to use your full name instead of your login name defined through the predefined variable ${USER}, use the following construct:
    #set( $MyName = "John Smith" )

    Reference link

    • File Template Variables
    0 讨论(0)
  • 2021-01-23 22:05

    It's a bug in IntelliJ IDEA, filed as https://youtrack.jetbrains.com/issue/IDEA-154958. Thanks for noticing!

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