Update (25-Jun-05):
- Renamed the entry to be less version-specific.
- Fixed a bug with non-static previews. (Thanks, TweezerMan.)
- Worked around a bug in <MTRemoteSignInLink> and <MTRemoteSignOutLink>.
- 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.
-
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.
-
Install The Compare Plugin
If your Movable Type installation doesn’t already have it installed, download and install Kevin Shay’s Compare plugin.
-
Create A New “Comment Fields” Template Module
On the main Templates page, scroll down to the Template Modules section and click on Create new templates module.
Name the template “Comment Fields”.
Copy and paste the contents of this file into the Module Body field.
Save the new template module.
Next, we need to edit our templates so they’ll reference our shiny, new template module.
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>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>
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>
-
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:
TweezerMan (aka David Phillips), for the original concept and code.
Hirotaka Ogawa, for solving the TypeKey refresh problem.
Chad Everett, for the javascript changes required to use the
idattribute in theformtag.And many others I’m sure I’m forgetting…