I'm trying to find a way to enable javascript syntax highlighting while editing a VF page inside eclipse.

Has anyone had success in enabling this?


I haven't had much success in getting JavaScript Syntax Highlighting to work when editing a Visualforce Page in Eclipse.

However, if you create a JavaScript file (.js) and upload it as a Static Resource, you can then open that file in Eclipse (with the JavaScript editor, which has Syntax Highlighting).

To use a JavaScript Static Resource in a Visualforce Page, use the <apex:includeScript /> tag.

<apex:includeScript value="{!URLFOR($Resource.Your-Resource-Name)}" />

To open the Static Resource JavaScript file, make sure you add the Static Resources Metadata to your project.

  1. Once your JavaScript Static Resource is downloaded, right click the file name from the Package Explorer in Eclipse.
  2. Select "Open With..." then "Other...". enter image description here

  3. Once the "Editor Selection" window shows up, select the JavaScript Editor. enter image description here

To use merge fields, include them between <script> tags before the JavaScript Static Resource is included (using <apex:includescript />).

<!-- Visualforce variables used by custom scripts -->
<script type="text/javascript">
    var __AccountName = "{!Account.Name}";
| improve this answer | |
  • Thanks, not exactly the answer to the question but it is a way to get syntax highlighting for javascript! – Phil B Apr 10 '13 at 20:22
  • What if you have merge fields in your javascript? – Phil B Apr 10 '13 at 20:45
  • 1
    To include merge fields, assign them to variables (var __AccountName = "{!Account.Name}";) in a <script type="text/javascript"> tag before your <apex:includescript> tag. – Matt K Apr 10 '13 at 21:57
  • awesome thanks! – Phil B Apr 11 '13 at 14:23

Install "HTML Editor (standard) 3.5.1" plugin on you eclipse. Search it on the eclipse marketplace (Help -> Eclipse Marketplace). It worked fine for me. Remember you must restart eclipse after installation

| improve this answer | |

If you are putting the Javascript in its own file (which I suggest in most circumstances), you should have no problem with the highlighting. Even inside a Visualforce page, if you put it within <script> tags, the syntax highlighting should pick it up. I am surprised you are not already experiencing that.

If this is not the case for you, I may not be able to help you. However, allow me to give an alternative solution. I would suggest putting any Javascript into a StaticResource. You can zip up all of your CSS and Javascript and access it through a StaticResource using the URLFOR() function. This will externalize your Javascript for reusability and keep any logic out of the view.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.