How to manage templates in NetBeans I

NetBeans contains many predefined templates for creating new files, but these templates don't have to fit your needs and you want to change or create new templates. I will try to explain it from PHP point of view, but this is generic NetBeans future, no PHP specific. Originally I have prepared one blog entry about this, but then I realized that this is too long. There is the first part, which describes "static" templates.

Basically it's very simple. You can do it from Template Manager, which is opened after invoking Templates item in Tools menu.

As you can see from the picture you can add, delete, rename or sort the templates as you want. You can also open the selected template in editor and change its content or you can create new template category. For example I have created new category My PHP Templates, then I added three PHP files and one html file to this folder. All these files I had somewhere on my local disk. In the moment when you add a file as a template, NetBeans copy the file into your userdir (place where NetBeans store settings) and from this moment NetBeans works with this copy.

All changes, what I have done in the Template Manager, are reflected in the New File Wizard.

There is also other way how to add new template. If you have a file in a project and you think that this file is suitable for new template, then you can invoke Save As Template... action from context menu over the file.

After invoking Save As Template... a simple dialog is opened to choose the category, where  the new template will be placed. As in the previous case, the file is copied to your userdir and you can edit or remove the original file without changing template. If you want to change the content of the template, rename or delete the template, you can do it in the Template Manager.

This was easy. In the continue of this I will describe how you can write templates, which are process with a scripting engine and the content is altered during creating new file.

Comments:

Petr, thanks for blogging about templates in NetBeans. It's helped to identify problems or weakness in handling of file-templates in NetBeans IDE. Many of problems were fixed in NetBeans 7.0 Milestone1. I've blogged about it at http://blogs.sun.com/rechtacek/entry/improved_handling_of_file_templates.

Posted by Jiri Rechtacek on December 05, 2008 at 09:36 AM CET #

tt

Posted by guest on June 03, 2009 at 07:33 AM CEST #

Hello,

By mistake, I deleted the PHP folder in the Template Manager.

Now, I can't even create a new PHP web page by right clicking in my PHP project!!!

Do you know how can I fix this?

Hugo

Posted by Hugo on June 11, 2010 at 06:55 PM CEST #

Hi Hugo,

probably the easiest way would be to install new version of NB or delete / start NB with new userdir.

Posted by Petr Pisl on June 14, 2010 at 04:21 AM CEST #

Brilliant!

This will be extremely useful for creating controllers, form and models for use with some of the (as yet) unsupported PHP frameworks such as CodeIgniter and also for our inhouse Framework.

The only question I have is; can templates be exported/imported?

Posted by Andrew McCombe on July 07, 2010 at 11:16 AM CEST #

@Hugo For NetBeans 6.9, Your template settings are stored in ~/.netbeans/6.9/config/Templates.

To reset your template settings, simply exit NetBeans and remove that directory. When you restart NetBeans, the default templates will be restored (though any modifications you made to the default templates will be lost).

There is a Scripting directory within the Templates directory that appears to contain custom/changed templates. With some experimentation, you might find a way to restore any customized templates after/while restoring the default sets.

Earlier versions of NetBeans might function similarly.

Posted by Phoenix on July 22, 2010 at 08:39 AM CEST #

Hi,
I wonder if there is way to make active customization for the new file templates like those found in code templates?
In other word, to be able to make something like setting active parts for the new file name:
${app}_controller.php this should make the -app- to be highlighted.
Also it should provide some active cursor areas which may do something like the following:

class ${app}Controller extends app_controller{

}

In this case ${app} should be introduced like the -app- entered in the file name.

Posted by Said Bakr on August 22, 2010 at 08:49 PM CEST #

Hi,

I want to make a template so that if I change the template all the pages made with that template needs to update,
Is it possible ?

Fahaz

Posted by guest on November 24, 2013 at 12:09 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

This blogs is written by NetBeans developers who contribute to the PHP support mainly.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today