Netbeans Template配置

一直用Netbeans写php,从来没配置过模板,模板配置好,可以省很多事,而且,显得很专业,今天到netbeans官方网站找了一些东西,配置好模板,方便开发。
新建php文件时:

<?php
/**
* Encoding     :   UTF-8
* Created on   :   2009-10-23 14:48:40 by smallchicken , [email protected]
*/
?>

工具--模板--打开php里面的--“PHP 文件”,在编辑器中打开,
好,可以编辑模板文件。
当然,如果要写入时间和文件名之类的变量需要单独配置变量。

<?php
/**
* Encoding     :   ${encoding}
* Created on   :   ${date} ${time} by ${author} , ${email}
*/

?>
变量需要在  工具--模板--用户配置属性--User.properties   在编辑器中打开
[email protected]
author=smallchicken
${date?date?string("yyyy-m-d")}
${time?time?string("H:i:s")}

写入变量就可以了。
日期和时间的格式和php相同,
变量名字可以自己定义。

官方的模板变量名列表:
http://wiki.netbeans.org/FaqTemplateVariables

Can you give me a list of all the predefined variables for templates, like ${user} and ${date}?

  • ${date} inserts the current date, in this format: Feb 16, 2008
  • ${encoding} inserts the default encoding, such as: UTF-8
  • ${name} inserts the name of the file.
  • ${nameAndExt} inserts the name of the file, together with its extension.
  • ${package} inserts the name of the package where the file is created.
  • ${time} inserts the current time, in this format: 7:37:58 PM
  • ${user} inserts the user name.
  • ${project.license} based on the value (e.g., 'CDDL'), the license header is found and is inserted into the template.
  • ${project.name} inserts the project name
  • ${project.displayName} inserts the project displayname

For more details, go here.

How do I override those predefined variables?

  1. Go to Tools | Templates.
  2. Scroll to the end of the Template Manager and expand 'User Configuration Properties'.
  3. Select 'User.properties' and click 'Open in Editor'.
  4. Now you can add the above and set your own value, for example:
[email protected]

Now, whenever you have ${user} in a file template, you will find the above value generated into the file that you create using that template.

Note: The ${date} variable is of type String, not type Date. You have to cast it to a Date type then do the format. For example, to show the year only, do this:

${date?date?string("yyyy")}
其实还是蛮好配置的

你可能感兴趣的:(Netbeans)