Getting SmartyPDT working with PDT (Eclipse 3.3.2) and .html file extensions
I use Eclipse as my Integrated Development Environment (IDE) for working on PHP projects - the fantastic PDT Project provides a PHP Development Tools framework for the Eclipse platform. it is a great free alternative to Zend Studio. I make extensive use of the Smarty Template Engine in nearly all of my PHP projects - so when I came across the SmartyPDT plugin for Eclipse which supports syntax highlighting, code completion, runtime Smarty errors and debug capabilities, I was keen to give it a go.
Unfortunately I ran into a number of problems getting this plugin running, but I managed to solve all of them. As of writing I am running latest release version of PDT which is currently 1.0.3 (built on Eclipse 3.3.2).
Error opening the Editor
After installing SmartyPDT 0.5.4, which is the latest version in the Featured Downloads section, I encountered the following error when trying to open a Smarty .tpl file in Eclipse:
Error opening the editor.
tried to access field org.eclipse.php.internal.ui.editor.PHPStructuredEditor.isExternal from class org.eclipse.php.smarty.ui.editor.SmartyStructuredEditor
After a little digging, I found a re-built version of SmartyPDT (0.5.5) as an attachment to one of the Issues on the Google Code project pages (it also claims to fix problems with Java 6 (jre 1.6.0), which is what I’m using). It is installed in exactly the same way:
- Extract the contents of the .zip into the parent folder above your Eclipse PDT installation.
- Start Eclipse and go to the Help menu > Software Updates > Manage Configuration.
- Tick the icon marked “Show Disabled Features” - it’s third in from the left on my Eclipse.
- Expand the Eclipse Platform tree, and find the Smarty Feature 0.5.5 entry.
- Choose Enable under Available Tasks (you may first need to Disable the Smarty Feature 0.5.4 entry).
- Restart Eclipse.
This re-built version 0.5.5 solved the above error for me.
File extensions other than .tpl are not using the SmartyPDT plugin
The SmartyPDT plugin by default is only configured to work with .tpl files. If like me you use the .html file extension for your template files (I actually use .tpl.html), then you will find that these files are not highlighted by the SmartyPDT plugin.
You need to add *.html files to the Smarty Template content type - Window > Preferences > General > Content Types > Text > PHP Content Type > Smarty Template > Add
But it’s already associated with the HTML content type and adding it to the Smarty Template content type has no effect. It also can’t be removed from the HTML content type as it is locked - “*.html (locked)” - because it has been defined by the HTML plugin.
However, it can be disabled by manually editing the HTML plugin.xml file. In order to do this, first close down Eclipse and browse to the Eclipse installation directory, and in the plugins directory, find the .jar file beginning with org.eclipse.wst.html.core - this can be opened in WinRAR or similar. Extract the plugin.xml file and open it in your favourite text editor.
Find the extension element with point property whose value is org.eclipse.core.runtime.contentTypes, and remove html from the file-extensions property of the content-type sub-element.
This is what it should look like after editing:
<extension point="org.eclipse.core.runtime.contentTypes">
<content-type
file-extensions="htm,xhtml,htpl,wml,shtml,shtm"
priority="high"
name="%HTML_Content_Type_Extension_Element.name"
id="htmlsource"
base-type="org.eclipse.core.runtime.text">
<!-- note: no default-charset for HTML, should use 'platform' -->
<describer
class="org.eclipse.wst.html.core.internal.contenttype.ContentDescriberForHTML" />
</content-type>
</extension>
Now save the file and put it back into the .jar file, overwriting the existing plugin.xml file.
Start up Eclipse again and SmartyPDT should now be activated for .html files!

One Comment, Comment or Ping
Andrew
Hello.
Good to know!
Dec 11th, 2008
Reply to “Getting SmartyPDT working with PDT (Eclipse 3.3.2) and .html file extensions”