How to work with templates
Hi ! I'm trying to add some templates (and then use them) in my plugin, but I couldn't make it work.
I'm implementing FileTemplateGroupDescriptorFactory and registering the extension point, it is executed and it's adding some new entries on Settings > File Templates.
But I don't know how to fill those templates, should I create an *.ft file?
Please a bit lost with this, can you explain me better how it works and what should I do?
Thanks !!
Enrique.
Please sign in to leave a comment.
OK, this is what I have so far:
I have created a file called "Test.php.ft" inside "fileTemplates" package (not fileTemplates.j2ee), and I've added ";?*.ft" to the compiler options, the template is now added automatically (and with content) to the "Templates" tab, even more, I don't need the extension point for this.
And I can get the content of the template using:
Hi Enrique,
As you correctly figured out, your .ft file should be placed under the "fileTemplates" directory somewhere in your plugin's classpath.
This is so colled "default" template category.
There are also several predefined template categories:
"internal", "includes", "code", "j2ee";
fileTemplates/internal, fileTemplates/includes etc.
For obtaining a template depending on its category use corresponding methods:
FileTempleteManager.getTemplate()
FileTempleteManager.getPattern()
Regards,
Eugene Zhuravlev
Thanks Eugen, so I can't create my custom tab with my custom group and icons?
If I use
Then it creates e agroup with my icons, but inside the tab Java EE tab.
And If I don't use anything and just put the files inside "fileTemplates" it adds the templates automatically, but with the default icon according to the extension and it also shows the templates when user uses Alt+Insert.
> so I can't create my custom tab with my custom group and icons?
You can't create a custom tab, but you can create a custom group in a way you mentioned.
The group will be displayed under the J2EE tab. The name of the tab is legacy and indeed counterintuitive. I think we'll change it. Thanks for pointing on this.
Eugene.