---
name: "Dancer2::Core::Role::Template"
section: "3pm"
platform: "linux"
package: "libdancer2-perl"
version: "1.1.2+dfsg-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/Dancer2::Core::Role::Template"
---

# Dancer2::Core::Role::Template(3pm)

Role for template engines

## NAME

Dancer2::Core::Role::Template - Role for template engines

## VERSION

version 1.1.2

## DESCRIPTION

Any class that consumes this role will be able to be used as a template engine under Dancer2.

In order to implement this role, the consumer **must** implement the method `"render"`. This method will receive three arguments:

- $self

  - $template

  - $tokens

  Any template receives the following tokens, by default:

- •

  `"perl_version"`

  Current version of perl, effectively `$^V`.

- •

  `"dancer_version"`

  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 the equivalent of `"$request->params"`.

- •

  `"vars"`

  The list of request variables, which is what you would get if you called the `"vars"` keyword.

- •

  `"session"`

  The current session data, if a session exists.

## ATTRIBUTES

### name

The name of the template engine (e.g.: Simple).

### charset

The charset.  The default value is **UTF-8**.

### default\_tmpl\_ext

The default file extension.  If not provided, **tt** is used.

### views

Path to the directory containing the views.

### layout

Path to the directory containing the layouts.

### layout\_dir

Relative path to the layout directory.

Default: **layouts**.

### engine

Contains the engine.

## 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. Can be used for either views or layouts:

```
    $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

### apply\_renderer($view, \\%tokens)

### apply\_layout($content, \\%tokens, \\%options)

### process($view, \\%tokens, \\%options)

### template($view, \\%tokens, \\%options)

## AUTHOR

Dancer Core Developers

## COPYRIGHT AND LICENSE

This software is copyright (c) 2024 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.
