Visualforce Code Templates/Snippets for Force.com IDE!
I recently saw a lot of action around Mac’s favorite editor, TextMate. The Force.com community has done a great job creating a full-fledged IDE (integrated development environment) and various code templates for ease of use.
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 on Windows machines, and a few of the geeks are using Ubuntu, too. So, I am always more motivated to do something using Force.com IDE.
Force.com IDE is already doing a decent job on top of Eclipse. It provides a nice Visualforce editor with syntax highlighting and code indentation based on the 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. The rest of the post describes how.
How do you set up Visualforce code templates for Eclipse?
Here are the steps:
#1 Goto Eclipse > Preferences.
#2 Search for “Template” in the left pane preference filter box, as shown below.
#3 Hit the “New” button on the extreme right side to start creating a new “Template”, as shown:
#4 In the next dialog, enter the tag name in the text field labeled “Name” and the code snippet in the text area labeled “Pattern”. Also, select context as “HTML Tag”, as shown below:
#5 Now, on any Visualforce page in Force.com IDE, press CTRL + SPACE and start typing the tag name, like “apex:p…” You will see the newly created template below in the content assist box. Hit enter to get the template inserted in the current code location.
Using the same steps as above, I have created a few templates for Visualforce, like:
Creating a helpful template library for Visualforce!
The good part about Eclipse templates is that they can be exported and imported back via XML. I started creating a few code snippets/templates, and the export for them is available in the 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 the “Export” button.
Please join me in adding more and better code templates for making Visualforce development easier in Eclipse.
Lets Talk
Have questions? We’re here to help! Drop a comment below or connect with us through our social media channels. Whether you’re a Salesforce developer, admin, or consultant, we hope this guide helps you get insights on creating Visualforce code templates/snippets for IDE!
Drop a note with your queries to move forward with the conversation 👇🏻