1Dancer::Template::AbstrUascetr(3C)ontributed Perl DocumeDnatnacteiro:n:Template::Abstract(3)
2
3
4

NAME

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

VERSION

10       version 1.3400
11

DESCRIPTION

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

TEMPLATE TOKENS

18       By default Dancer injects some tokens (or variables) to templates. The
19       available tokens are:
20
21       "perl_version"
22           The current running Perl version.
23
24       "dancer_version"
25           The current running Dancer version.
26
27       "settings"
28           Hash to access current application settings.
29
30       "request"
31           Hash to access your current request.
32
33       "params"
34           Hash to access your request parameters.
35
36       "vars"
37           Hash to access your defined variables (using "vars").
38
39       "session"
40           Hash to access your session (if you have session enabled)
41

INTERFACE

43       init()
44           The template engine can overload this method if some initialization
45           stuff has to be done before the template engine is used.
46
47           The base class provides a plain init() method that only returns
48           true.
49
50       default_tmpl_ext()
51           Template class that inherits this class should override this method
52           to return a default template extension, example: for
53           Template::Toolkit it returns "tt" and for HTML::Mason it returns
54           "mason".  So when you call "template 'index';" in your dispatch
55           code, Dancer will look for a file 'index.tt' or 'index.mason' based
56           on the template you use.
57
58           Note 1: when returning the extension string, please do not add a
59           dot in front of the extension as Dancer will do that.
60
61           Note 2: for backwards compatibility abstract class returns "tt"
62           instead of throwing an exception 'method not implemented'.
63
64           User would be able to change the default extension using the
65           "<extension"> configuration variable on the template configuration.
66           For example, for the default ("Simple") engine:
67
68                template: "simple"
69                engines:
70                  simple:
71                    extension: 'tmpl'
72
73       view($view)
74           The default behavior of this method is to return the path of the
75           given view, appending the default template extension (either the
76           value of the "extension" setting in the configuration, or the value
77           returned by "default_tmpl_ext") if it is not present in the view
78           name given and no layout template with that exact name existed.
79           (In other words, given a layout name "main", if "main" exists in
80           the layouts dir, it will be used; if not, "main.tmpl" (where "tmpl"
81           is the value of the "extension" setting, or the value returned by
82           "default_tmpl_ext") will be looked for.)
83
84       view_exists($view_path)
85           By default, Dancer::Template::Abstract checks to see if it can find
86           the view file calling "view_exists($path_to_file)". If not, it will
87           generate a nice error message for the user.
88
89           If you are using extending Dancer::Template::Abstract to use a
90           template system with multiple document roots (like Text::XSlate or
91           Template), you can override this method to always return true, and
92           therefore skip this check.
93
94       layout($layout, $tokens, $content)
95           The default behavior of this method is to merge a content with a
96           layout.  The layout file is looked for with similar logic as per
97           "view" - an exact match first, then attempting to append the
98           default template extension, if the view name given did not already
99           end with it.
100
101       render($self, $template, $tokens)
102           This method must be implemented by the template engine. Given a
103           template and a set of tokens, it returns a processed string.
104
105           If $template is a reference, it's assumed to be a reference to a
106           string that contains the template itself. If it's not a reference,
107           it's assumed to be the path to template file, as a string. The
108           render method will then have to open it and read its content
109           (Dancer::FileUtils::read_file_content does that job).
110
111           This method's return value must be a string which is the result of
112           the interpolation of $tokens in $template.
113
114           If an error occurs, the method should trigger an exception with
115           "die()".
116
117           Examples :
118
119               # with a template as a file
120               $content = $engine->render('/my/template.txt', { var => 42 };
121
122               # with a template as a scalar
123               my $template = "here is <% var %>";
124               $content = $engine->render(\$template, { var => 42 });
125

AUTHOR

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

AUTHOR

130       Dancer Core Developers
131
133       This software is copyright (c) 2010 by Alexis Sukrieh.
134
135       This is free software; you can redistribute it and/or modify it under
136       the same terms as the Perl 5 programming language system itself.
137
138
139
140perl v5.28.0                      2018-06-15     Dancer::Template::Abstract(3)
Impressum