Reputation: 77
trying to use the HTMLTemplateProRenderer
plugin for
Mojolicious::Lite
so that I can use template files in the style of HTML::Template
.
The issue is that every example, even documentation, only shows the template file attached to the script. I need the template file to be in a different directory from the Perl code.
Here is a sample of what I am trying to do.
This works using __DATA__
, but how could it work by using an external template file as this:
#!/usr/bin/env perl
use Mojolicious::Lite;
plugin 'HTMLTemplateProRenderer';
# Route leading to an action that renders a template
get '/test' => sub {
my $c = shift;
$c->stash( one => 'This is result one' );
$c->render(
template => 'display/index',
two => 'this is the second',
handler => 'tmpl'
);
};
app->start;
The template file is display/index.tmpl
<html>
<head><title>Test Template</title>
<body>
<p>Value ONE = <TMPL_VAR NAME="one"> </p>
<p>Value TWO = <TMPL_VAR NAME="two"> </p>
</body>
</html>
Upvotes: 2
Views: 556
Reputation: 2520
First, the template path must be in the format <name>.<format>.<handler>
. So for display/index
is display/index.html.tmpl
.
Second, a template search paths for HTMLTemplateProRenderer
are templates
and templates/<controller>
relative to app home. And app home if used plugin config option tmpl_opts => {use_home_template => 1}
. Or any path added to app->renderer->paths
.
Upvotes: 1