Dancer2...Template(3)
π Dancer2::Core::Role::Template β the manual, but make it a group chat π
okay so bestie, you found the Dancer2...Template(3) page in the User Contributed Perl Documentation section and honestly? iconic of you. this is the role that makes template engines work under Dancer2. let's get into it π
β¨ NAME β¨
Dancer2::Core::Role::Template β the role for template engines. that's it, that's the whole name, no notes π
πΈ VERSION πΈ
version 2.2.1
π¦ DESCRIPTION π¦
so here's the tea: any class that consumes this role can be used as a template engine under Dancer2. that's the whole vibe. you want your own template engine? consume the role, bestie π«Ά
but listen β to actually implement this role, the consumer must implement the method render. no skipping, no shortcuts, it's giving required. and that render method receives three arguments:
$self
$template
$tokens
now, every template gets these tokens by default, and they're lowkey the best part:
perl_versionβ the current version of perl, which is effectively$^V. slay.dancer_versionβ the current version of Dancer2, effectivelyDancer2->VERSION.settingsβ a hash of the application configuration.requestβ the current request object.paramsβ a hash reference of all the parameters. currently this is the equivalent of$request->params.varsβ the list of request variables, which is literally what you'd get if you called thevarskeyword.sessionβ the current session data, if a session exists. (if it doesn't? no session token for you, sorry not sorry π)
π ATTRIBUTES π
name
the name of the template engine (e.g.: Simple).
charset
the charset used by the template engine. this is typically set from the application's charset setting.
default_tmpl_ext
the default file extension. if you don't provide one, tt is used. defaults are so real.
views
path to the directory containing the views.
layout
path to the directory containing the layouts.
layout_dir
relative path to the layout directory. the default is layouts.
engine
contains the engine. it's holding the engine. main character energy fr fr.
π METHODS π
view_pathname($view)
returns the full path to the requested view.
layout_pathname($layout)
returns the full path to the requested layout.
pathname_exists($pathname)
returns true if the requested pathname exists. you can use it for either views or layouts, it's flexible like that:
$self->pathname_exists( $self->view_pathname( 'some_view' ) );
$self->pathname_exists( $self->layout_pathname( 'some_layout' ) );
render_layout($layout, %tokens, \$content)
render the layout with the applied tokens. note the backslashes bestie, those are references, we respect them here.
apply_renderer($view, %tokens)
apply_layout($content, %tokens, %options)
process($view, %tokens, %options)
template($view, %tokens, %options)
π AUTHOR π
Dancer Core Developers. absolute legends, no cap.
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2026 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. free as in freedom, free as in iconic π
ngl bestie, that's the whole page. consume the role, implement render, respect the tokens, and you're golden β¨
and that's a wrap! this was Dancer2...Template(3) from perl v5.42.3, dated 2026-09-20. go forth and template responsibly, you ate π
ππ¦
π¦ where this page comes from
- fedora 44: perl-Dancer2 2.2.1-1.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms