in reply to Re^2: Mojolicious HTMLTemplateProRenderer
in thread HTML::Template Plugin

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

Replies are listed 'Best First'.
Re^4: Mojolicious HTMLTemplateProRenderer
by Anonymous Monk on Feb 15, 2017 at 13:50 UTC
    Hi, I know the code would work with the "SelfLoader", I am trying to make it work without any template code attached to the Perl code, without this part:
    __DATA__ @@ hi.html.tmpl <p> from __DATA__ its @@ hi.html.tmpl <p> <TMPL_VAR NAME="t1">
    and load it separated, this template code would be in its own directory, like in /templates or something. Thanks!

      Hi, I know the code would work with the "SelfLoader", I am trying to make it work without any template code attached to the Perl code, and load it separated, this template code would be in its own directory, like in /templates or something. Thanks!

      Hi,

      Look closer at Re^3: Mojolicious HTMLTemplateProRenderer, look at the perl foo.pl calls, I'm showing that it works

      On first run, template from __DATA__ is used

      On second run, after I rename not_templates to templates, templates/hi.html.tmpl is used

      On third run, after I rename not_exists to exists, exists/hi.html.tmpl is used