Dancer::Template::Abstract(3pm) | User Contributed Perl Documentation | Dancer::Template::Abstract(3pm) |
Dancer::Template::Abstract - abstract class for Dancer's template engines
version 1.3521
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.
By default Dancer injects some tokens (or variables) to templates. The available tokens are:
The base class provides a plain init() method that only returns true.
Note 1: when returning the extension string, please do not add a dot in front of the extension as Dancer will do that.
Note 2: for backwards compatibility abstract class returns "tt" instead of throwing an exception 'method not implemented'.
User would be able to change the default extension using the "<extension"> configuration variable on the template configuration. For example, for the default ("Simple") engine:
template: "simple" engines: simple: extension: 'tmpl'
If you are using extending Dancer::Template::Abstract to use a template system with multiple document roots (like Text::XSlate or Template), you can override this method to always return true, and therefore skip this check.
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.
Dancer Core Developers
This software is copyright (c) 2010 by Alexis Sukrieh.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
2023-02-10 | perl v5.36.0 |