Creating a Global Modifier

Template Tag Modifiers transform the contents of the tag's value.

Declaring Global Modifiers

To declare a plugin's template tags you will need to augment your plugin's init_registry subroutine. This subroutine is called automatically when the plugin is loaded by Movable Type during the initialization phase. It should specify via the plugin's built-in "registry" function the simple data structure that should be merged with Movable Type's core registry.

The code:

sub init_registry {
    my $plugin = shift;
    $plugin->registry({
        tags => {
            modifier => {
                'lolcat' => \&_fltr_lolcats,
            },
        },
    });
}

These subroutines are then called each time one of these global modifiers are invoked via a template tag:

sub _fltr_lolcats {
    my ($str, $val, $ctx) = @_;
    return "LOL - CAN I HAZ A $str";
}

Here are the input parameters passed to any global modifier:

  • str - The value of the template tag
  • val - The value passed into the global modifier attribute
  • ctx - A reference to the template's context

See Also

This page was last updated on 2007-08-10, 15:02.  

Leave a note

Have a question, please use the MT Forums. Notes sumbitted here should pertain to tips & hints regarding documentation.