2

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>
Borodin
  • 126,100
  • 9
  • 70
  • 144
Maresia
  • 67
  • 2
  • 2
  • 6
  • What happens if you run this? – simbabque Feb 15 '17 at 16:27
  • Also there's a typo, you are missing a `'`. – simbabque Feb 15 '17 at 16:56
  • bad arguments: expected filename or scalarref at /usr/local/lib64/perl5/HTML/Template/Pro.pm line 198. But how? Thats what I cant figured it out. – Maresia Feb 15 '17 at 18:20
  • Did you try adding the file extension? – simbabque Feb 15 '17 at 21:06
  • as this? $c->render(template => 'display/index', format => 'tmpl', handler => 'tmpl'); - Yes, didn't work! – Maresia Feb 15 '17 at 21:26
  • No, I meant in the `template`. Try `display/index.tmpl`. – simbabque Feb 15 '17 at 21:37
  • 1
    That wouldn't make any difference, I tried before, Mojolicious::Lite, takes care of it without the extension, the module I am trying to use is where the issue is "HTMLTemplateProRenderer" I will contact the author since the documentation doesn't show any sample on how to do it like that. – Maresia Feb 16 '17 at 16:57

1 Answers1

1

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.

Denis Ibaev
  • 2,470
  • 23
  • 29