Using a Template Parameter Transformation Callback
Template Parameter callbacks are invoked after a template has been “compiled,” or in layman’s terms, after the template has been initially processed by the system, but prior to it being rendered into HTML. At this point, one can no longer access the template’s source code directly. You can however traverse the template’s DOM using an API virtually analogous to Java Script’s DOM traversal and manipulation interfaces.
A template parameter callback also gives developers the opportunity to inspect and modify the data that will be used to seed the template with the information that will ultimately be rendered to the screen as HTML.
Let’s first look at the parameters passed to a callback of this type, and then follow up with some example code.
Input Parameters
- $cb - a reference to the current
MT::Callback
object handling this event. - $app - a reference to the
MT::App::CMS
object processing this request. - $param - a reference to the parameter hash that is populated with the data that will be used in rendering the current template
- $tmpl - the actual
MT::Template
object representing the current page
Sample Code
sub xfrm {
my $plugin = shift;
my ($cb, $app, $param, $tmpl) = @_;
# do something
}
See Also
- Manipulating the MT::Template DOM