Mojolicious::Lite with Template Toolkit
Asked Answered
P

1

7

I'm trying to get Template Toolkit to work as the default renderer in Mojolicious::Lite. What I have:

use strict;
use warnings;

use Mojolicious::Lite;
use Mojolicious::Plugin::TtRenderer;
plugin tt_renderer => { template_options => { INCLUDE_PATH => './tmpl', DEBUG => 1 } };

get '/' => sub {
  my $self = shift;

  $self->render( 'index' );
};

app->renderer->default_handler( 'tt' );
app->start;

When I try to hit the test server, I get:

[Fri Oct 12 14:02:02 2012] [info] Listening at "http://*:3000". 
Server available at http://127.0.0.1:3000. 
[Fri Oct 12 14:02:08 2012] [debug] Your secret passphrase needs to be changed!!! 
[Fri Oct 12 14:02:08 2012] [debug] GET / (Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:16.0) Gecko/20100101 Firefox/16.0). 
[Fri Oct 12 14:02:08 2012] [debug] Routing to a callback. 
[Fri Oct 12 14:02:08 2012] [debug] Nothing has been rendered, expecting delayed response.

This happens regardless of what I pass as parameters to 'render'. I can't seem to figure out how to get any useful debugging information out of this; but I haven't used Mojo before.

I've confirmed by sprinkling in some warn statements that my get handler is being called.

Panelist answered 12/10, 2012 at 18:6 Comment(2)
Was TMPL_ROOT meant to be INCLUDE_PATH? Template::Toolkit doesn't render anything if it can't find the template.Crusted
Ack, yeah, not sure where TMPL_ROOT came from. (It's Friday.) I'm still seeing the same behavior though. :(Panelist
P
10

After looking at the source of Mojolicious::Plugin::TtRenderer::Engine, I figured it out. The plugin ignores the INCLUDE_PATH option passed to Template Toolkit, and instead gets the path from $app->renderer_paths. So updating my code to include:

app->renderer->default_handler( 'tt' );
app->renderer->paths( [ './tmpl' ] );

makes it work.

Panelist answered 12/10, 2012 at 18:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.