May 2, 2005

Blog Operations Department

Bad Movable Type!

Let's take a look at a picture of Ripley:

Ripley

Ripley

The HTML for that looks like this:

<div class="art-photo-l">
<a href="/archives/2005/images/20050401-IntroducingRipley.jpg"
title="Ripley"><img alt="Ripley"
src="/archives/2005/images/20050401-IntroducingRipley-thumb.jpg"
width="400" height="300" />
</a>
<p>Ripley</p>
</div>

(I've simplified the HTML in these examples slightly for readability, so they may not work as shown.)

That's kind of messy, especially when I have to do that for every photo I want to post. I often get it wrong.

Even worse, if I want to do a blog-wide change to something about the photos, I have to edit every entry that has photos. (Unless the change only affects the CSS and not the HTML.)

So I wanted to try replacing those big HTML blocks with something simpler that abstracts away the HTML that implements it. I started by using Brad Choate's MTMacro plugin for Movable Type. It's well documented and easy to use, so within a few minutes I had boiled the text down to something like this:

<MTWpArtPhoto
  image="20050401-IntroducingRipley"
  title="Ripley"
>

And it worked great. I'd type this little bit of code to replace the photo HTML in each blog entry—which made them a lot simpler—and the HTML sent to the browser was the same as before. The only difference is that I don't have to maintain each one separately.

I'd changed about a half-dozen of them when I remembered I also had to change the templates for the various archives. After making the change, I clicked on an individual article link and got this message:

The requested page could not be found.

Smarty error: [in mt:35 line 15]:
syntax error: unrecognized tag 'MTMacroApply' 
(Smarty_Compiler.class.php, line 556)

Now archive templates are just like the main template, except that I have all the archives set up for dynamic rebuilding. When a visitor requests one of those pages, Movable Type builds it and serves it on the fly. I do this so I don't have to rebuild all the blog pages whenever I make a template change. The main page, however, is static. That's for efficiency, so it doesn't have to be rebuilt every single time a visitor checks it.

I disabled dynamic content and rebuilt the entire web site, and sure enough, everything worked fine. So MTMacro doesn't work in dynamic mode for some reason. Well, it hasn't been maintained in a while, so perhaps it missed a Movable Type upgrade. Fine. I'll build my own special-purpose Movable Type plugin to implement the MTWpArtPhoto tag.

It took about an hour of tinkering to figure out how plugins worked and to create a dummy plugin to test with. I tried it with dynamic pages and it didn't work at all. The MTWpArtPhoto tag just got copied into the outgoing page. A little more research led me to the Process Tags plugin, which allows you to turn on tag processing in blog content. Try it again...another error message.

What the heck? It's almost like plugins are broken in Movable Type with dynamic content. But that can't be, because all those plugins are such big part of Movable Type...time to do some research.

Well, it turns out SixApart did break plugins in dynamic templates. Plugins that add new tags have to be built with PHP and/or something called SMARTY. I didn't bother to look up what that is. It would be nice if SixApart had documented this.

Movable Type's dynamic publishing mode supports plugins as well. The architecture is different, but should be familiar in some respects.

That's it. That's all they said about plugins. I don't know about the rest of you, but it's not immediately obvious to me that this means that dynamic publishing is implemented in a completely different way from static publishing and all the old plugins won't work.

I wrote a simple dynamic plugin, and it doesn't look too hard, but it only works for the dynamic pages, not the static main page. I'd have to jump through the hoops to make the main page dynamic too, and that will be a bit inefficient. If I want it to work both ways, I'll have to implement both Perl and PHP versions of the tag. And I still haven't tested if PHP plugins work from blog content...

I'm sure there's some reason why the developers did it this way, but the result is frustrating as hell.

UPDATE: I decided to try to implement both versions of the MTWpArtPhoto tag after all. This required me to program in two languages I hardly ever use: Perl and PHP.

The first step was to figure out how to get the new PHP-based plugins to be processed in the blog content. With the Perl plugins, I used the Process Tags plugin from Adam Kalsey. It allows me to do this in the template:

<MTEntryBody process_tags="1">

That's all it takes to get Movable Type to expand tags in the blog content on static pages. However, Kalsey hasn't gotten around to implementing the "process_tags" attribute in PHP yet, so it doesn't work on dynamic pages. I took a look at how the Perl version is implemented and decided to try to implement my own version.

It looks like this:

<?php
function smarty_modifier_process_tags($body,$args) {
    global $mt;
    $ctx =& $mt->context();
    if ($ctx->_compile_source('entry body', $body, $_var_compiled)) {
	    ob_start();
	    $ctx->_eval('?>' . $_var_compiled);
	    $_contents = ob_get_contents();
	    ob_end_clean();
	    return $_contents;
    } else {
        return '<p><strong>Error compiling blog entry'
        . 'with Process Tags.</strong></p>' . $body;
    }
}
?>

I based this on the implementation of the MTInclude tag, and there are parts of it I don't understand that I just put in there because they were in MTInclude. In other words, this is cargo-cult programming. But it seems to work.

I'm now working my way back through all the older blog entries and modifying them to use the new photo tag.

Leave a comment

About this Entry

This page contains a single entry by Mark Draughn published on May 2, 2005 1:41 PM.

Buffy Napping was the previous entry in this blog.

Virginia, Spelled V-A-L-K-E-N-V-A-N-I-A is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Find us on Facebook

Unless you request otherwise, we will assume all messages are for publication and attribution.

Red links are Not Safe For Work NSFW.

Mark

About Mark

PGP key

Visit Mark on MySpace

Joel

About Joel

Visit Joel at twincitiescarry.com

Gary

About Gary

Article Syndication

Bloggy Goodness

Hit & Run
Cataloguing every inch of our daily slide down the slippery slope towards a more totalitarian state.
Virgina Postrel
Author, columnist, and famous kidney doner.
InstaPundit
Law professor, author, columnist, music engineer, the founding father of the blogosphere.
Marginal Revolution
Smart economists.
StrategyPage
News and commentary on all things military.
Focal Point
Lindsay Beyerstein, your basic working philosopher.
The Agitator
Radley Balko, libertarian at large.
Nobody's Business
Pro-Liberty. Anti-Nannies.
A Stitch in Haste
Kip Esquire, mad twitterer.
Last One Speaks
A complicated woman with simple tastes.
Ravings of a Feral Genius
The one, the only, Jennifer.

War on Drugs

StoptheDrugWar.org
Taking the drug war debate to the blogosphere
DrugWar Rant
More reasons every week for hating the War on Drugs.
DUI Blog
The road to hell is paved with good intentions and patrolled by Mothers Against Drunk Driving.
The D'Alliance
The Drug Policy Alliance blog.
Vigil for Lost Promise
A counterweight to the DEA's exploitive site.

Blawgs

Indefensible
David Feige, creator of Raising the Bar and former public defender.
a Public Defender
Rants, explanations, and complaints from a public defender.
Simple Justice
Rants, explanations, and complaints from a private lawyer.
Defending People
The art and science of criminal defense trial lawyering
ECILCrime
East Central Illinois criminal defense.
Austin Criminal Defense Lawyer
A decent blawg despite the SEO-friendly name.
Underdog Blog
Criminal defense, politics, and God only knows what else.
CrimLaw
A big, goofy, ballcap-wearing prosecutor who even likes dogs.
Blonde Justice
Funny stories about criminal defense.
Crime & Federalism
Legal analysis and bitching.
Seeking Justice
Tom McKenna, Virginia prosecutor on a mission from God.
Not Guilty
A lawyer in search of a clue.
Woman of the Law
Defendin', datin', drinkin'.
The Volokh Conspiracy
Smart legal experts.
Norm Pattis
Norm will fight for you!
The Legal Satyricon
Entertainment and First Amendment Law
Gamso - For the Defense
An Ohio criminal defense lawyer
Crime and Consequences Blog
Because we're just not punishing people enough
Criminal Defense
It's like a criminal defense blog, but from Florida
D.A. Confidential
Making prosecutors seem just like normal lawyers
Graham Lawyer Blog
Interesting writing about the law.
The Matlock Blog
Young Shawn Matlock discusses criminal law in Texas and beyond
New York Personal Injury Law Blog
Better than you'd think from the SEO-friendly name
West Virginia Criminal Law Blog
Also better than you'd think from the SEO-friendly name
South Carolina Criminal Defense Blog
And one more that's better than you'd think from the SEO-friendly name

Geek Stuff

The Daily WTF
Crazy stories about bad things inside computer software and how they got there.
xkcd
Extremely geeky comics
Google Blogoscoped
Smart writing about search engine technology.

Economics

Steven Landsburg
The Armchair Economist
Greg Mankiw's Blog
Aurhor of the most popular macroeconomics textbook
Marginal Revolution
The margins are where everything happens
Megan McArdle
Business and economics

Photography

Strobist
How to light everything in the world with speedlights
iN-PUBLiC.com
Very cool modern street photography.
Digital Photography Review
Detailed reviews of digital cameras and vicious forum debates too.
Ken Rockwell
Strong opinions about photography.
Dan Heller
Photographs and the business of photography.
Bert P. Krages II
Photography and the law.

Chicagoland

BlogNetNews.com/Illinois
The Illinois blogosphere's front page.
Leslie's Omnibus
I have no idea what this blog is about.
Marathon Pundit
John Ruberry runs, drives, and blogs.

Media

Eric Zorn
Real blogging at the Chicago Tribune, with real blogging software.
Miss Manners
A marvelous writer and deeper than you think.
Roger Ebert's Journal
A great writer and a useful film critic.

Resources

Institute for Justice
A merry band of libertarian litigators.
EFF: Bloggers
The Electronic Frontier Foundation's page for bloggers.
CIA World Factbook
A brief summary about every nation.
Wikipedia
The mostly-useful encyclopedia of everything.
Current Impact Risks
It has to happen some day.

Gone But Not Forgotten

Peter McWilliams
Ain't Nobody's Business If You Do

Web Rings

Credits

Copyright  ©  2002-2007 Mark Draughn. All rights reserved.

Site developed by
Draughn Software Corporation

Powered by Movable Type 4.261
Version 4.261

Downtown Host

Social networking tags courtesy of the Sociotags for Movable Type plugin by Ole Wolf.

Chicago lakefront image by Ken Gibson.

Admin

Valid XHTML 1.0 Transitional

Valid CSS

ICRA

Statistics

Adorama