May 31, 2006

Hacking Movable Type

While playing with the new tags feature I started with adding it to the main page of my site. The problem is that my older posts don't have any tags associated with them. The naive approach would just attach an empty "Tags: " line to each of those old posts. But even for my unskilled UI hacking skills that would be lame. There doesn't seem to be any kind of way to get the count of the number of tags associated with an entry in the Tags.app API. Doing some digging I did run across the MTIfNonEmpty template tag. I figured I could use that along with the MTTagsList widget to determine if a post had any tags.

Alas, it didn't work. Looking at the generated HTML there was a lot of excess whitespace. Thankfully I stumbled onto the trim filter. The documentation seems to indicate that the trim filter applied to the MTIfNonEmpty template tag would solve my problem.

Alas, it didn't work. After adding some debugging output to the MTIfNonEmpty template tag and the trim filter it looks to evaluate the value returned by the tag before applying the filters to the value. As a result the whitespace isn't getting trimmed correctly. Instead of trying to figure out why the call order looks to be out of order, I decided to take the easier approach and modify the definition of the MTIfNonEmpty test. The diff is below:

*** ./lib/MT/Template/ContextHandlers.pm~ Wed Aug 17 17:50:11 2005 --- ./lib/MT/Template/ContextHandlers.pm Thu May 4 23:54:42 2006 *************** *** 493,499 **** my $handler = $ctx->handler_for($args->{tag}); if (defined($handler)) { my $value = $handler->($ctx, { %$args }); ! if (defined($value) && $value ne '') # want to include "0" here { _hdlr_pass_tokens($ctx, $args, $cond); } else { --- 493,499 ---- my $handler = $ctx->handler_for($args->{tag}); if (defined($handler)) { my $value = $handler->($ctx, { %$args }); ! if (defined($value) && $value !~ /^\s*$/) # want to include "0" here { _hdlr_pass_tokens($ctx, $args, $cond); } else {

In short the template tag now considers any value that is only whitespace as being empty. I think given the nature of HTML (or XHTML) and optional whitespace, that this is a reasonable interpretation. Now to add the tags to other pages on the site, tag some of my older posts, and then see what my tag cloud starts to look like.

Tags: movabletype mt programming tags

May 31, 2006

Tags

I'm trying out a tagging plug-in for MT. I've not decided how good it is, but I figured I'd give it a try. It's called Tags.App. They have a nominal donation request, which is why I'm interested in trying it before spending any money. My first issue, like I've complained about in the past, is that the documentation for the product is pretty bad. I'm not an MT hacker by any means and the minimal documentation left me out in the cold. I'll have to see if I can figure out enough to make it work.

Tags: movabletype mt tags