The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Response TemplateToolkit - View plugin using template toolkit

SYNOPSIS

        my $response = $hector->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 Hector actions to just display a static page.

The display() can additionally be called by a controller action multiple times if several different templates need to be output.

METHODS

new($hector)

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.

getTemplateVar($name)

        $response->getTemplateVar("name");

Returns the value of the given template variable.

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:

        $PSGI::Hector::Response::SimpleTemplate::templateLoc = "../root";

See also

Template

Author

MacGyveR <dumb@cpan.org>

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

See Also

Copyright

Copyright (c) 2017 MacGyveR. All rights reserved.

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