MTElse Fix For Plugins

February 27, 2003 - updated February 8, 2006

The built-in <MTElse> tag only works with built-in conditional tags such as MTEntryIfExtended. It does not work with plugin conditional tags, such as MTEntryIfComments. This hack modifies MovableType to support MTElse in any conditional plugin tag.

lib/MT/Builder.pm Modification

Go to your MovableType installation directory, and open the file Builder.pm in the lib/MT subdirectory.

  1. Find the line (line 98 in MT 2.63) that says:
                my($tokens, $uncompiled);
    and add the following line after it:
                my $tokens_else;
  2. Find the line that says:
                        $tokens = [ grep $_->[0] ne 'Else', @{ $t->[2] } ];
    and add the following line after it:
                        $tokens_else = [ grep $_->[0] eq 'Else', @{ $t->[2] } ];
  3. Find the line that says:
                    $ctx->stash('tokens', $tokens);
    and add the following line after it:
                    $ctx->stash('tokens_else', $tokens_else);

lib/MT/Template/Context.pm modification

Go to your MovableType installation directory, and open the file Context.pm in the lib/MT/Template subdirectory.

  1. Find the section (line 43 in MT 2.63) that says:
            if ($condition->(@_)) {
                return _hdlr_pass_tokens(@_);
            } else {
                return '';
            }
    and replace it with the following section:
            if ($condition->(@_)) {
                return _hdlr_pass_tokens(@_);
            } else {
                my($ctx, $args, $cond) = @_;
                return $ctx->stash('builder')->build($ctx, $ctx->stash('tokens_else'), $cond);
            }