NAME

Response TemplateToolkit - View plugin using template toolkit

SYNOPSIS

my $response = $mungo->getResponse();
$response->setTemplateVar("hello", $something);

DESCRIPTION

This view plugin allows you to read a template file and replace placholders with scalar variables.

With this class you can specify empty Mungo actions to just display a static page.

METHODS

new($mungo)

Constructor, All environment hash is saved in template variable "env" and the current action is saved as "action" so they can be accessed along with any other variables stored during the server action in the usual template toolkit way.

setTemplate($template)

$response->setTemplate("login");

Manually set the template to display.

An file extension of '.html' will be automatically appended to this name.

The template will be fetched from the template directory, See the Notes section for more details.

display()

$response->display();

This method is called automatically at the end of an action.

A template is automatically chosen. An example demonstrates how this is done.

URL used: /foo/bar/app.cgi?action=login Template chosen: app-login.html

setError($message)

$response->setError("something has broken");

Set an error message for the response, which is accessible in the error template as [% message %].

setTemplateVar($name, $value)

$response->setTemplatevar("name", "Bob");

Creates a template variable with the specified name and value. The variable may be of any type and can be access from the template in the usual way.

Notes

If an error occurs a template called "genericerror.html" will be used instead of the specified template. Please make sure you have this file, there is an example of this in the "root/templates" directory of this module.

To change the template location use the following code at the top of your script:

$CGI::Mungo::Response::SimpleTemplate::templateLoc = "../root";

Sess also

Template

Author

MacGyveR <dumb@cpan.org>

Development questions, bug reports, and patches are welcome to the above address

Copyright

Copyright (c) 2012 MacGyveR. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.