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, effectively Dancer2->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 the vars keyword.
  • 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.


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