Subject: | template name is always undef in the build sub |
template is defined incorrectly inside MojoX::Renderer::Mason->build
method.
at the moment it looks like this:
return sub {
my ($mojo, $ctx, $output) = @_;
my $stash = $ctx->stash;
my $template = $stash->{template};
...
template here will always be undef, because in MojoX::Renderer->render
you can see the following:
my $template = delete $c->stash->{template};
...
my $options =
{template => $template, format => $format, handler => $handler};
...
elsif ($template || $handler) {
# Render
return unless $self->_render_template($c, \$output, $options);
# Extends?
$c->stash->{content}->{content} = b("$output")
if ($c->stash->{extends} || $c->stash->{layout}) && !$partial;
}
...
so the code should be rewritten as follows, for example:
return sub {
my ($mojo, $ctx, $output, $options) = @_;
my $stash = $ctx->stash;
my $template = ($options and ref($options) and ref($options) eq
'HASH') ? $options->{template} : $stash->{template};
...