Tiny Pineapple

ananas comosus (L.) minimus


Update (25-Jun-05):

  1. Renamed the entry to be less version-specific.
  2. Fixed a bug with non-static previews. (Thanks, TweezerMan.)
  3. Worked around a bug in <MTRemoteSignInLink> and <MTRemoteSignOutLink>.
  4. This version has been tested with Movable Type 3.17.

The Problem

Movable Type 3 introduced a new method for constructing comment forms. Rather than the old-fashioned way of building the fields (Name, Email, URL, etc) from scratch, they introduced a new tag called <MTCommentFields> that automatically generated the entire comment form for you.

But being a bit of a control freak, I didn’t like the fact I could no longer customize the form to my liking. And since I also suffer from occasional bouts of Validation OCD, I didn’t like the fact that <MTCommentFields> generated code that failed to validate. So it warmed my anal-retentive heart when I stumbled upon TweezerMan’s A Replacement for <MTCommentFields>. His solution resolved my control issues and some moderate tweaking of the template restored my validation mojo.

But after a recent upgrade to Movable Type 3.16, it stopped working. And after poking around a bit, I figured out why.

In addition to <MTCommentFields>, Movable Type 3 also introduced a new, but undocumented, template tag called <MTIfNonZero>. The only reference to it you’ll find in the Movable Type documentation is in one of the Category Template Tag examples:

<MTIfNonZero tag="MTCategoryCount">
<li><a href="<$MTCategoryArchiveLink$>" title="<$MTCategoryDescription$>"><MTCategoryLabel></a>
<MTElse>
<li><MTCategoryLabel>
</MTElse>
</MTIfNonZero>

From the example we can deduce that you can use <MTIfNonZero> to determine whether or not the value of a certain template tag is zero. But TweezerMan went one step further and used it to determine whether or not the value of a variable was equal to zero. And to do so, he used two different syntaxes:

<MTIfNonZero tag="GetVar" name="preview"><$MTCommentPreviewAuthor$></MTIfNonZero>

…and…

<MTIfNonZero tag="MTGetVar" name="preview"><$MTCommentPreviewAuthor$></MTIfNonZero>

But while those may have worked in Movable Type 3.15, neither seems to work in Movable Type 3.16.

But what Movable Type taketh away, plugins giveth…so here’s how you can get things working again using Kevin Shay’s Compare plugin.

The Solution

First, a disclaimer…

Disclaimer

This is a personalized scratch for my own particular itch. It may work for you; it may not.

We’re not doing anything particularly tricky here, but any change to your environment carries with it a certain amount of risk. Read through the instructions and only proceed if you feel comfortable with the steps described.

And while comments and/or corrections are always welcome, we feel it’s only fair to warn you that our entire Technical Support staff was laid off last year after a series of questionable expenditures on gender-specific pharmaceuticals and an unpleasant experience with the Nigerian banking industry.

In short, if something goes horribly wrong…you’re on your own.

  1. Back Up Your Existing Templates

    We’re going to be making changes to four of the existing templates:

    • Individual Entry Archive Template
    • Comment Listing Template
    • Comment Preview Template
    • Comment Error Template

    At the very least, you should copy and paste the contents of those four templates into a text file so you can revert back to the originals if anything untoward should happen.

  2. Install The Compare Plugin

    If your Movable Type installation doesn’t already have it installed, download and install Kevin Shay’s Compare plugin.

  3. Create A New “Comment Fields” Template Module

    1. On the main Templates page, scroll down to the Template Modules section and click on Create new templates module.

    2. Name the template “Comment Fields”.

    3. Copy and paste the contents of this file into the Module Body field.

    4. Save the new template module.

    Next, we need to edit our templates so they’ll reference our shiny, new template module.

  4. Edit Your Individual Entry Archive Template

    In your Individual Entry Archive Template, replace the following chunk of code:

    <MTEntryIfCommentsOpen>
    
      ...a whole lotta lines of code in between the 
      opening and closing MTEntryIfCommentsOpen tags...
    
    </MTEntryIfCommentsOpen>

    …with this:

    <MTEntryIfCommentsOpen>
      <MTIfCommentsAllowed>
    
        <h2>Post A Comment</h2>
    
        <$MTSetVar name="preview" value="0"$>
        <$MTSetVar name="static" value="1"$>
        <$MTInclude module="Comment Fields"$>
    
      </MTIfCommentsAllowed>
    </MTEntryIfCommentsOpen>
  5. Edit Your Comment Listing Template

    In the Comment Listing Template, replace this:

    <MTIfCommentsAllowed>
    
      <h2>Post A Comment</h2>
    
      <MTCommentFields>
    
    </MTIfCommentsAllowed>

    …with this:

    <MTIfCommentsAllowed>
    
      <h2>Post A Comment</h2>
    
      <$MTSetVar name="static" value="0"$>
      <$MTSetVar name="preview" value="0"$>
      <$MTInclude module="Comment Fields"$>
    
    </MTIfCommentsAllowed>
  6. Edit Your Comment Preview And Comment Error Templates

    In both the Comment Preview Template and Comment Error Template, replace this:

    <MTIfCommentsAllowed>
    
      <MTCommentFields preview="1">
    
    </MTIfCommentsAllowed>

    …with this:

    <MTIfCommentsAllowed>
    
      <h2>Make Changes Or Post</h2>
    
      <$MTSetVar name="preview" value="1"$>
      <$MTInclude module="Comment Fields"$>
    
    </MTIfCommentsAllowed>
  7. Rebuild Your Individual Archives

    Since the Comment Listing, Preview, and Error Templates are generated dynamically, you’ll be able to see your changes to those templates immediately, but you’ll need to rebuild your Individual Archive pages to see your changes reflected there.

Conclusion

That’s it. You now have a tidy, attractive, reusable, valid, and working solution for all your comment form needs. Tweak it to your heart’s (and eye’s) content.

Credits

As Fran Lebowitz once said:

“Original thought is like original sin: both happened before you were born to people you could not have possibly met.”

So, as this represents no original thought on my part, credit should go to the following people I’ve never met:


With the release of Movable Type 3.16, Six Apart finally got around to documenting all of the possible configuration settings you can use in your mt.cfg file. But while they provide a subset of that same information as comments in the default mt.cfg, I always wished they would include all of the same information so I wouldn’t have to keep hopping back and forth between the documentation and the file itself.

Well, I finally decided to do something about it, so here it is: a fully-commented mt.cfg file.

Maybe someone else will find it useful.

« Prev Next »