How do I register class templates from plugin?

Hi,
     I am trying to create java files from custom java templates. When I tried to add the template to 'fileTemplates/internal' folder, the 'class' keyword in the template text is getting replaced with lowercased template name by TemplateManager class. I tried to place the template in 'fileTemplates/j2ee', but now the TemplateManager can't find my template.

Can someone please tell me, where should I keep plugin specific templates? Is there any other configuration needed to expose the resources folder?

Thanks,
Stanley

2 comments
Comment actions Permalink

I just added templates to my plugin yesterday. It was a little confusing.

All you have to do is put the templates in fileTemplates or one of its subfolders make sure that you have named the files correctly. You need <template name>.java.ft and you call the template manager using the name <template name>.java (without the *.ft).

Make sure you are calling the right method on the template manager:

 FileTemplateManager.getInstance().getTemplate(templateName)


It will return an instance of BundledFileTemplate if you do it correctly.

One thing you need to do is make sure that if you are compiling with IDEA you need to add *.ft to compiler's resource patterns.

0
Comment actions Permalink

Thanks Jon!

That did the trick.

Thanks,
Stanley

0

Please sign in to leave a comment.