Teach TextMate about Smarty
TextMate is a text editor for Mac OS X that I first started to use while learning Rails. I’ve enjoyed it and have recently started to use it to edit some of my PHP projects. Out of the box however TextMate doesn’t really work with Smarty templates that well. In this post you’ll learn how to fix that. Internally TextMate uses bundles to manage lots of things, include knowledge about certain filetypes. By default you’ll get a bunch of useful bundles, but there are many more out there, including one for Smarty!
To follow along I’ll assume you have Subversion installed. If you don’t, there are various ways to install it. I outlined how I build Subversion in a recent talk I gave at PHAD. Martin also has a binary distribution (search his blog for the latest one, currently 1.3) and Darwin Ports is yet one more option.
The first thing we are going to do is make an Application Support folder for TextMate Bundles (if one does not already exist). We’ll make it in the root level Library folder so that all users will benefit from our addition. Should you want to limit the new bundles to your user, install the Application Support folder in you own home folder using the tilde in your path, like ~/Library/, and be sure to adjust these commands.
mkdir -p /Library/Application\ Support/TextMate/Bundles
After you have created this cd into it.
cd /Library/Application\ Support/TextMate/Bundles
From here we will use Subversion to do a checkout of the TextMate repository:
svn --username anon --password anon co \
http://macromates.com/svn/Bundles/trunk/Bundles/Smarty.tmbundle
After you’ve done the checkout you’ll need to tell TextMate to actually use the bundle. To do so, open a TextMate document window. Within the status bar at the bottom you’ll need to select Edit Languages... from the languages popup list.


This will bring up the Bundle Editor. Select HTML in the language list and then scroll down about 3/4 of the way down. You should see some code that mentions Smarty. Within that block look for a line of code that reads disabled = 1; and edit it to say disabled = 0;

Once this is done so are you. From now on TextMate will highlight any {smarty} stuff using the bundle you downloaded.
Some notes:
Should the Smarty Bundle be updated simply execute a Subversion update command to get the latest and greatest:
cd /Library/Application\ Support/TextMate/Bundles
svn up *.tmbundle
To keep track of bundle updates there is a handy RSS feed.
If you want to know more about bundles I’d recommend reading the TextMate manual.
Special thanks to Allan Odgaard who originally taught me this.
Posted on: January 4, 2006 – 10:36 pm


13 Comments
Thanks for this!
I’ve been using the smarty bundle without the bundle of the settings change in the html bundle for quite awhile now, this makes a big difference!
It seems like the smarty bundle should have a help section in it like the one in the SQL bundle, explaining this little bit of extra config.
Glad you found this helpful Bob.
Hey - this just made my day and confirmed my switch to TextMate. Ive been using a combination of Dreamweaver and others and they all choke on Smarty. Nolonger a problem.
Thanks Again!
Any thoughts on how to incorporate the Smarty triggers into the HTML bundle?
Sorry Ryan, I don’t have any experience or thoughts “incorporate the Smarty triggers into the HTML bundle.”
While trying to download (checkout) this bundle I got this error:
How can I download this bundle ? Thanks.
I just checked it out fine. Make sure your are not checking it out in another svn folder maybe? Or maybe this was a fluke as they were doing updates?
I’d try again. Else, email TextMate for support (as I don’t manage their svn repo).
Done! I was using the wrong folder… Thanks
When I type on the line that is SMARTY the TextMate, now, beeps. Why is that and how can I silence it? Thanks
First of all, thanks for this article as it got me up and running quickly with my first svn bundle.
In regards to getting the snippets/tab triggers working. I notice two problems. First off is that the scope for all the snippets is text.html.smarty which is wrong. You are in text.html when you invoke a smarty snippet (except for the modifiers I guess). If you change the scope to text.html they will work as advertised (remember to click out of the snippet in the editor in order for it to be saved/applied). Secondly, they don’t work with smart typing. The tab triggers start with a curly brace, which will automatically create the closing brace, then the trigger creates a redundant brace.
I also have to nitpick the snippets that are literally equal to their tab triggers? What’s the point?
Anyway, I really appreciate the effort that went into creating the smarty bundle, but I’d like to see a lot more. Maybe I’ll get off my ass and try to contribute… mabe :)
Hello, thanks for that nice hint. I’m using Smarty within my Xoops-Projects, where Smarty uses <{}> instead of {}. How can I tell the Smarty-Bundle to recognize <{}> ?
If you are using different delimiters you’ll probably have to edit the bundle yourself. I’m not its author so I can’t really say where the edit(s) are needed.
Good luck.
I found that the Smarty Bundle is no longer at the location given in this article. It is now at: http://macromates.com/svn/Bundles/trunk/Bundles/PHP Smarty.tmbundle/
So the command to get it would now be:
svn --username anon --password anon co \ "http://macromates.com/svn/Bundles/trunk/Bundles/PHP Smarty.tmbundle/"I also did not find an option to “Edit Languages…” in the Language popup at the bottom of TextMate. Instead, I found it under Bundles->Bundle Editor->Show Bundle Editor which brought up the dialog box mentioned here. (Note that you want to choose the Languages category)
Post a Comment | Comment RSS feed