diff --git a/lib/Mojolicious/Plugin/TtRenderer/Engine.pm b/lib/Mojolicious/Plugin/TtRenderer/Engine.pm index ab4d729..b7d83ea 100644 --- a/lib/Mojolicious/Plugin/TtRenderer/Engine.pm +++ b/lib/Mojolicious/Plugin/TtRenderer/Engine.pm @@ -87,9 +87,12 @@ sub _render { my $provider = $self->tt->{SERVICE}->{CONTEXT}->{LOAD_TEMPLATES}->[0]; $provider->options($options); $provider->ctx($c); + $provider->not_found(0); my $ok = $self->tt->process(defined $inline ? \$inline : $t, @params); + return 0 if $provider->not_found; + # Error die $self->tt->error unless $ok; @@ -152,6 +155,7 @@ sub new { sub renderer { @_ > 1 ? $_[0]->{renderer} = $_[1] : $_[0]->{renderer} } sub ctx { @_ > 1 ? $_[0]->{ctx} = $_[1] : $_[0]->{ctx} } sub options { @_ > 1 ? $_[0]->{options} = $_[1] : $_[0]->{options} } +sub not_found { @_ > 1 ? $_[0]->{not_found} = $_[1] : $_[0]->{not_found} } sub _template_modified {1} @@ -175,6 +179,7 @@ sub _template_content { # Try DATA section if(defined $options) { $data = $self->renderer->get_data_template($options); + $self->not_found(1) unless defined $data; } else { my $loader = Mojo::Loader->new; foreach my $class (@{ $self->renderer->classes }) { diff --git a/t/default_template.t b/t/default_template.t new file mode 100644 index 0000000..7f5ca9b --- /dev/null +++ b/t/default_template.t @@ -0,0 +1,36 @@ +use strict; +use warnings; +use Test::More tests => 3; +use Test::Mojo; + +use Mojolicious::Lite; + +# Tell Mojolicious we want to load the TT renderer plugin +app->plugin( + tt_renderer => { + template_options => { + # These options are specific to TT + INCLUDE_PATH => 'templates', + COMPILE_DIR => 'templates_c', + COMPILE_EXT => '.ttc', + # ... anything else to be passed on to TT should go here + }, + } +); + +app->renderer->default_handler('tt'); + +get '/' => sub { + die 'foo'; +}; + +my $t = Test::Mojo->new; + +$t->get_ok('/') + ->status_is(500) + ->content_like(qr{foo}); + +__DATA__ + +@@ index.html.tt +anything