This can be done in two different ways:
First add the before_render hook and set the variable. It's easy to pack it all inside the plugin:
package Mojolicious::Plugin::TemplateName; use Mojo::Base 'Mojolicious::Plugin'; sub register { my ($self, $app, $conf) = @_; $app->helper('template' => sub { return shift->stash('mojo.template') }); $app->hook(before_render => sub { my $c = shift; $c->stash('mojo.template', $_[0]->{template} ) }); } 1;
and use it inside a template like this
<%= template %>
Secondly, this can be done inside the templates - by setting a variable inside the template itself:
% stash('template', __FILE__);
and then reusing the variable in the layout:
<%= $template %>
In this case, you will receive a file name with a suffix and thatβs all - not just with the template.
Inspired by the answer here that templates are visualized inside out.
simone
source share