:: mcavity.com
July 14, 2004
Brad Choate's MTIfEmpty Plugin
A neat solution from Brad Choate
by gautam

Here’s a nifty trick in Movable Type. I’ve started using the <MTIfEmpty> (or, more accurately, the <MTIfNotEmpty>) tag to replace the <MTEntryIfExtended> tag.  

I use the Textile Plugin to get those smart, handsome-looking punctuations — curly quotes, real em-dashes and such. The “convertbreaks” option is set off (= “0”). Also, I like to have my pages (especially the longer entries) paginated. For this, I use the MTPaginate plugin. Both are excellent. My default formatting option is set to Textile2 and, for pagination, I use a setting of sectionstarttag= “p”; and maxsections= “4”. This means that Paginate will create a new page after four paragraphs, when it encounters the <p></p> tag pair. (Note that the maxwords variable is ignored when you use the max_sections= “N” variable)

The trouble starts when your HTML code contains the MT tag <MTEntryIfExtended> tag. The MT Manual says this:

A container tag: the contents of this container will be displayed if this entry has extended text associated with it. This can be useful on an index template for displaying a “More…” link, where you only wish to display this link if there is “more” text.

Unfortunately, when you use this tag with Textile and Paginate, it fails completely. It assumes that there is extended text (ie, that the “EntryMore” field is populated). This is because Textile generates the <p></p> tag pair even around the entry body (the text preceding the extended entry), and because Paginate looks to the <p></p> tag pair for deciding how many paras to show on a page.

The result? No matter what you do, your ‘extender text’ (something like “continue reading …” or “more …”) will always show up on every page where you use the <MTEntryIfExtended> tag. Basically, that tag and its pair, is deluded into thinking there is an extended body even if there isn’t.

If you want to suppress the continuer text (“more…”, etc) and use Textile and Paginate, you must use Broad Choate’s MTIfEmpty plugin. Simply replacing MTEntryIfExtended tag(s) with one that goes <MTIfNotEmpty var=”EntryMore”> works a charm as it actually checks to see if the EntryMore field has been populated or not.

I actually prefer the ‘negative’ tag from the MTIfEmpty plugin (thoughtful of Brad to provide that). Logically, it’s neater — instead of doing:

    {If (IsEmpty=True) THEN (do NOT do this)}

it allows the more elegant:

     {If (IsNotEmpty=True) THEN (DO this)}

This will always return an accurate result.

This way, your continuer text will show only if there is anything to continue to!

Another tweak, by the way, is using the IfEmpty plugin to generate or not generate a whole row or cell (or even a table) when you’re working with HTML tables. All you need to do is to put the MTIfEmpty (or MTIfNotEmpty) tag pair outside the table/row/cell opening and closing tags and that’s it. The plugin evaluates the condition and, if met, generates the table. This is very useful when you want to insert text into a given place in your HTML but delete the space it would occupy when it’s not there, deleted or archived off by date. 

© 2004 gautam  ::
gautam@gautampatel.com  ::