Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi there Monks!

I am trying to learn if I can use HTML::Template with Mojolicious::Lite using this plugin called "HTMLTemplateProRenderer". I just cant find any exemple on how to read an external template file and pass some values to the template file using HTML::Template style. This code will display the template but no values get inserted into the template.
Here is the code I am trying with:
#!/usr/bin/env perl use Mojolicious::Lite; plugin 'HTMLTemplateProRenderer'; # Render template in "templates/index.tmpl" get '/test' => sub { my $c = shift; $c->render(template => 'index'); #$c->render('index'); # fill in some parameters $c->param(HOME => $ENV{HOME}); $c->param(PATH => $ENV{PATH}); }; app->start;

Here is the template file in templates/index.tmpl
<html> <head><title>Test Template</title> <body> My Home Directory is <TMPL_VAR NAME=HOME> <p> My Path is set to <TMPL_VAR NAME=PATH> </body> </html>

Thanks for looking!

Replies are listed 'Best First'.
Re: Mojolicious HTMLTemplateProRenderer
by beech (Parson) on Feb 15, 2017 at 01:06 UTC
      I tried loading the template file from another location, it's own directory and not within the code and I can't find a way to do it as well. Interesting!

        Hi,

        Did you use https://metacpan.org/pod/Mojolicious::Renderer#paths to tell mojo about this directory?

        update: foo.pl

        #!/usr/bin/env perl use Mojolicious::Lite; plugin 'HTMLTemplateProRenderer'; get '/' => sub { my $c = shift; return $c->render( 'hi', t1 => 'the first t1', ); }; my $paths = app->renderer->paths; unshift @$paths, 'exists'; app->start; __DATA__ @@ hi.html.tmpl <p> from __DATA__ its @@ hi.html.tmpl <p> <TMPL_VAR NAME="t1">

        $ perl foo.pl get / [Tue Feb 14 19:24:14 2017] [debug] GET "/" [Tue Feb 14 19:24:14 2017] [debug] Routing to a callback [Tue Feb 14 19:24:14 2017] [debug] 200 OK (0.00174s, 574.713/s) <p> from __DATA__ its @@ hi.html.tmpl <p> the first t1 $ mv not_templates templates $ perl foo.pl get / [Tue Feb 14 19:24:27 2017] [debug] GET "/" [Tue Feb 14 19:24:27 2017] [debug] Routing to a callback [Tue Feb 14 19:24:27 2017] [debug] 200 OK (0.001793s, 557.724/s) <p> from templates its hi.html.tmpl <p>the first t1 $ mv not_exists exists $ perl foo.pl get / [Tue Feb 14 19:24:53 2017] [debug] GET "/" [Tue Feb 14 19:24:53 2017] [debug] Routing to a callback [Tue Feb 14 19:24:53 2017] [debug] 200 OK (0.001772s, 564.334/s) <p> from exists its hi.html.tmpl <p> the first t1
Re: HTML::Template Plugin
by Anonymous Monk on Feb 14, 2017 at 21:00 UTC
      I have seeing this before, but none of it shows how to use an external template file with it.