Not a developer? Go to MovableType.com

Documentation

Passing Data to a Template

The most critical component of a “template” is the ability to pass data into the template that is then dropped into pre-assigned locations. This after all is what makes something a “template” as opposed to a static HTML file.

Let’s begin by taking the above “Hello World” example and modifying who we want to say “Hello” to. First, let’s look at the template code:

<mt:setvarblock name="page_title">This is a page title</mt:setvarblock>
<mt:include name="include/header.tmpl">
<p>Hello <mt:var name="person">!</p>    
<mt:include name="include/footer.tmpl">

Place this template code in the following file:

/path/to/mt/plugins/MyPlugin/tmpl/some_template.tmpl

Now we need to modify the handler to pass the parameter called “person” into the template.

sub somemode {
    my $app = shift;
    my $input = $app->{query}->param('some_formparameter');
    my $plugin = plugin();
    my $param = {};
    $param->{person} = "Byrne";
    my $tmpl = $plugin->load_tmpl('sometemplate.tmpl');
    return $app->buildpage( $tmpl, $param );
}

Back

Leave a Comment