I recently saw a lot of action around Mac’s favorite editor TextMate. Force.com community has done a great job to create a full fledged IDE and various code templates for ease in working.
I like TextMate, but I am more inclined towards Force.com IDE, because of its platform neutral nature. Most of my force.com pals are either on Windows machines and few of the geeks are using Ubuntu too. So I am always more motivated towards doing something using Force.com IDE.
Force.com IDE is already doing a decent job on top of Eclipse. It gives a nice Visualforce editor, that gives syntax highlighting and code indentation based on standard Eclipse HTML Editor. I recently tried to create a couple of Visualforce code templates/snippets to quickly assist in creating the pages, and was successful in that attempt. Rest of the post describes how.
How to setup Visualforce code templates for Eclipse ?
Here are the steps
- Goto Eclipse > Preferences.
- Search for “Template” in the left pane preference filter box, as shown below
- Hit the “New” button on extreme right side to start creating a new Template, as shown :
- In the dialog next, enter tag name in the text field labeled “Name” and code snippet in text area labeled “Pattern”. Also select context as “HTML Tag”, as shown below :
- Now, in any visualforce page in Force.com IDE, press CTRL + SPACE and start typing the tag name, like apex:p… In the content assist box, you will see the newly created template as shown below. Hit enter to get the template inserted in current code location.
Using the same steps as above, I have created a few templates for visualforce like
Field Label Template
CRUD FLS Permission
Creating a useful template library for Visualforce !
The good part about Eclipse templates is those can be exported and imported back via XML. I started creating a few code snippets/templates and the export for them is available in gist here.
One can easily import this GIST on the same template page using the “Import” button near the New one. Similarly exporting yours is easy too, just select templates to export and hit “Export” button.
Please join me to add more and better code templates for making Visualforce development easier in Eclipse.