May 20, 2011

Drupal syntax highlighting in Aptana Studio 3

Aptana has long been my web-development IDE of choice, especially for building Drupal sites. It's extremely powerful out-of-the-box, it's free, and because it's built on Eclipse there are myriad plugins which add new functionality (SVN and git integration leap immediately to mind).

Configuring Aptana specifically for Drupal has always been a little finicky, however, so I'm putting together a series of quick tips to help optimize the installation / configuration process.

By default, Aptana Studio 3 provides syntax highlighting for most common web file extensions (HTML, JS, CSS, PHP, etc.). Any of Drupal's standard file extensions, however, .module, .theme, or .install extension is missing all of the syntax highlighting that (among other things) make IDEs so great to use.

Drupal files don't have any syntax highlighting in Aptana Studio 3 by default

Thankfully, we can configure Aptana to treat our Drupal files as PHP files, after which they'll always appear coloured and much easier to read.

  1. Select the "Window" item in the main menu bar
  2. Select the Preferences item in the dropdown menu
  3. Expand the General menu in the left-hand side of the window
  4. Expand the Editors menu in the left-hand side of the window
  5. Select the File Associations item from the expanded menu
  6. Next to the File Types list box, select the Add... button so that we can add our file type
    Select the "Add..." button next to the File Associations list box
  7. In the resulting field, enter an asterisk followed by a period followed by the file-extension you wish to add (e.g. '*.module')
  8. Select the Ok button
  9. With our new entry now added and selected / highlighted in the list of file types, select the Add... button to the left of the Associated Editors list box.
    Add a file editor for our Drupal content type
  10. Ensure that the "Internal Editors" radio button is selected and choose Aptana PHP Source Editor from the list. This will associate Aptana's internal PHP editor with our file type.
    Select 'Aptana PHP Source Editor' to use the PHP syntax highlighter with our Drupal files
  11. Repeat the previous 5 steps for each file type that you wish to add (*.module, *.install, *.theme, etc.)
    Our Drupal files now have proper syntax highlighting

That's it! Your Aptana Studio 3 installation will now highlight the syntax of your Drupal files properly.