View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Franck Cuny > Dancer-1.1902 > Dancer::Template::Abstract



Annotate this POD


View/Report Bugs
Source   Latest Release: Dancer-1.3400


Dancer::Template::Abstract - abstract class for Dancer's template engines


This class is provided as a base class for each template engine. Any template engine must inherit from it and provide a set of methods described below.



The template engine can overload this method if some initialization stuff has to be done before the template engine is used.

The base class provides a plain init() method that only returns true.


The default behavior of this method is to return the path of the given view.

layout($layout, $tokens, $content)

The default behavior of this method is to merge a content with a layout.

render($self, $template, $tokens)

This method must be implemented by the template engine. Given a template and a set of tokens, it returns a processed string.

If $template is a reference, it's assumed to be a reference to a string that contains the template itself. If it's not a reference, it's assumed to be the path to template file, as a string. The render method will then have to open it and read its content (Dancer::FileUtils::read_file_content does that job).

This method's return value must be a string which is the result of the interpolation of $tokens in $template.

If an error occurs, the method should trigger an exception with die().

Examples :

    # with a template as a file
    $content = $engine->render('/my/template.txt', { var => 42 };

    # with a template as a scalar
    my $template = "here is <% var %>";
    $content = $engine->render(\$template, { var => 42 });


This module has been written by Alexis Sukrieh, see Dancer for details.

syntax highlighting: