One of the (many!) nice things about Movable Type is its customizability. I didn’t realize just how far that extended until today.
I’d read previously in the MT UI that you can customize the output path for the archive files using Archive File Templates
, and I’ve done so to provide more usable URLs based on the page title since just after I started Petroglyphs. Recently, I wanted to do a similar thing for another site, except that not all of the entries are guaranteed to have titles. Using my existing template, <$MTArchiveDate format="%Y/%m/%d"$>/<$MTEntryTitle dirify="1"$>.html
, didn’t work because I wound up generating filenames like .html, but for a number of reasons (not least of all this) I didn’t want to add arbitrary characters or otherwise change the template.
MT plugins to the rescue. Brad Choate has written prolificly on MT, and developed a number of useful plugins that I’ve dutifully installed. The one that solved this problem, and made me appreciate MT more, is his MTIfEmpty. Basically what this does is check an expression–most often an MT tag itself–to see if it’s empty; the plugin also includes MTIfNotEmpty to do the opposite.
As it turns out, MT lets you use tags defined by plugins almost anywhere, not just in your page templates. (The one exception I’ve found is that you can’t use any tags directly in your entries–even built-in ones–although I’ve found a workaround for that too using another of Brad’s tools.) The practical upshot of this is that you can use plugins in your filename templates.
So without further ado, I present the template above, modified to use the filename untitled when appropriate: <$MTArchiveDate format="%Y/%m/%d"$>/<MTIfEmpty expr="[MTEntryTitle dirify='1']">untitled</MTIfEmpty><$MTEntryTitle dirify="1"$>.html