Six Apart Developer Wiki

The Movable Type and Professional Network Wiki has been moved to wiki.movabletype.org.

Recent Changes

TransformerPlugins

[Login] Change #2 by OpenID Identitydanwolfgang.myopenid.com at 2006-11-27 23:57:04.

Example:

MT->add_callback('MT::App::CMS::AppTemplateSource.__template__', 9, $plugin, \&_template);

sub _template {   
    my ($cb, $app, $template) = @_;   
    my $old = <<'END_HTML';   
The old plugin text!   
END_HTML

    $old = quotemeta($old);   
    my $new = <<'END_HTML';   
My new template text!   
END_HTML

    $$template =~ s/$old/$new/;   
}

Here's the tip:

I've gone crazy a few times trying--unsuccessfully--to select part of a template for replacement (that's the part held in $old). Here's the trick: sometimes the text to replace holds something that looks like a variable, and double-quoting the selection interprets that variable. You want to single-quote it instead. I like using a heredoc to select the template, where I use single quotes around the terminator.

In summary: if the replacement isn't working, maybe variables are being interpretted.

[Login] Change #2 by OpenID Identitydanwolfgang.myopenid.com at 2006-11-27 23:57:04.
Six Apart
Makers of weblog software and services for individuals, organizations and businesses.