X

An Oracle blog about NetBeans for PHP

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.

Join the discussion

Comments ( 8 )
  • Jiri Rechtacek Friday, December 5, 2008

    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.


  • guest Wednesday, June 3, 2009

    tt


  • Hugo Friday, June 11, 2010

    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


  • Petr Pisl Monday, June 14, 2010

    Hi Hugo,

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


  • Andrew McCombe Wednesday, July 7, 2010

    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?


  • Phoenix Thursday, July 22, 2010

    @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.


  • Said Bakr Sunday, August 22, 2010

    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.


  • guest Saturday, November 23, 2013

    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


Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.