NAME

Dancer::Template::TemplateSandbox - Template Toolkit wrapper for Dancer

DESCRIPTION

This class is an interface between Dancer's template engine abstraction layer and the Template::Sandbox module.

This template engine is recomended for production purproses, but depends on the Template::Sandbox module.

In order to use this engine, set the following setting as the following:

template: template_sandbox

This can be done in your config.yml file or directly in your app code with the set keyword.

Note that Dancer configures the Template::Sandbox engine to use <% %> brackets instead of its default <: :> brackets, it also sets template_toolkit_compat to true.

SETTINGS

You can pass additional options to the Template::Sandbox constructor from within the template_sandbox subsetting of the engines setting in your config.yml:

template: template_sandbox
engines:
    template_sandbox:
        open_delimiter: <:
        close_delimiter: :>

CACHING

You can enable and configure caching by setting the cache, cache_type and cache_dir settings.

cache may be one of 'cache_factory' or 'chi' to use Cache::CacheFactory or CHI respectively.

cache_type will set the cache type, 'file' and 'memory' should both be fine, but other values may or may not work.

cache_dir will need to be set if you set cache_type to 'file', but is otherwise ignored.

template: template_sandbox
engines:
    template_sandbox:
        cache: cache_factory
        cache_type: file
        cache_dir: /var/tmp/cache/dancer

template: template_sandbox
engines:
    template_sandbox:
        cache: chi
        cache_type: memory

TEMPLATE FUNCTIONS

In keeping with Template::Sandbox philosophy, no template functions are enabled by default.

You can load them as class-wide template functions from your myapp.pm:

package myapp;
use Dancer;

use Template::Sandbox qw/:function_sugar/;

Template::Sandbox->register_template_function(
    localtime => ( no_args inconstant sub { scalar localtime() } ),
    );

Or you can use template function libraries with class-level imports:

package myapp;
use Dancer;

use Template::Sandbox;
use Template::Sandbox::NumberFunctions qw/:all/;

The documentation in Template::Sandbox and Template::Sandbox::Library goes into more detail on both these scenarios.

SEE ALSO

Dancer, Template::Sandbox, Cache::CacheFactory, CHI

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Dancer::Template::TemplateSandbox

You can also look for information at:

AUTHORS

Sam Graham <libdancer-template-templatesandbox-perl BLAHBLAH illusori.co.uk>.

Based on work in Dancer::Template::TemplateToolkit by Alexis Sukrieh.

COPYRIGHT & LICENSE

Copyright 2010 Sam Graham, all rights reserved. Portions derived from work copright Alexis Sukrieh.

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