I was cleaning up my templates today and screwed a few things up. Thought I’d post about it to both document it and serve as a warning for other MT‘ers out there.

I usually link my templates to files for safekeeping. In this case, I was removing my old templates and renaming some of the new ones to the old names (for example, the “Banner” module was deleted and “New Banner” was renamed “Banner”). After that, I’d put an appropriate template file path in. What I didn’t realize immediately (it took two screw-ups for me to realize what I did) was that if the specified file already exists, MT takes its content and populates the template with it the first time the template is saved. This happened with my banner template first, and I fixed it by viewing source on a cached version of one of my pages. Before I realized what had happened (I thought it was some obscure bug), I removed my old stylesheet and updated the current one with the same template path and filename as the old. The subsequent reversion to the old style was particularly bad, since I’d customized the new stylesheet with a little layout and colors, and I couldn’t find a cached version of the stylesheet to roll back to.

Luckily, I didn’t do too much customization, so a little bit of work and now I’m back close to where I was. But I did things a little bit differently this time. Instead of customizing the stock MT 3.2 stylesheet, I added an MTInclude to the bottom of the template. It references a new “Custom-CSS” template module I created, where I added my own style additions (img.gravatar, img.left, and googlead) and re-stated the stock classes and IDs whose parameters (mainly colors) I’m altering. This is slightly wasteful from a CSS perspective since some rules are stated twice, but compared to the amount of overstatement already in the stock stylesheet it’s no big deal. This means in the future all I have to do to customize the stock stylesheet (which will inevitably become more streamlined in future releases) is to add a single line; the MTInclude to my Custom-CSS template.