Smarty template syntax highlighting with gedit

Update: I have posted an alternative way to do the same thing this post describes, the alternative way should be more reliable. See it here http://www.c3b.co.uk/2008/12/16/alternative-method-for-opening-smarty-templates-with-html-syntax-highlighting-in-gedit/

I’ve started using gedit as my code editor after a couple of niggles with bluefish and wanted my smarty templates (*.tpl) to use the same syntax highlighting as HTML. Not wanting to have to manually select the language each time I open a .tpl file I went searching for a way to add them to the definition of what an html file is. I was getting frustrated with all the references to a syntax highlighting tab in the preferences dialog that just didn’t exist! Even the help file in gedit 2.22.1 still mentions the syntax highlighting tab but I can assure you it’s not there.

The solution I came up with was to manually edit the HTML language definition file for gtksourceview which is what gedit uses to define the syntax highlighting. To achieve this you must change the following line in the /usr/share/gtksourceview-2.0/language-specs/html.lang file:

<property name="globs">*.html;*.htm</property>

to

<property name="globs">*.html;*.htm;*.tpl</property>

Or download my version here (html.lang) of the file and run the following command:

Backup existing file

cd /usr/share/gtksourceview-2.0/language-specs
sudo cp html.lang html.lang_bkup

Then move the downloaded version of the file into place (this assumes you download the file and extracted it to your home directory)

sudo mv ~/html.lang /usr/share/gtksourceview-2.0/language-specs/html.lang

Restart gedit and when you next open a .tpl file it will be highlighted in the same way as an HTML file.

3 thoughts on “Smarty template syntax highlighting with gedit

  1. I tried the proposed solution and nothing changed for Gedit. :(
    I can’t see the .tpl files in the browse panel. And if I open them from nautilus they are not highlighted…
    I’m using ubuntu 8.10 …
    Any suggestions?

  2. I have posted a new solution to this problem, I’ve added a link at the top of this post. Hopefully you’ll have more success with it.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>