diff --git a/lib/Mojolicious/Plugin/TtRenderer/Engine.pm b/lib/Mojolicious/Plugin/TtRenderer/Engine.pm index 8035bd4..a56f635 100644 --- a/lib/Mojolicious/Plugin/TtRenderer/Engine.pm +++ b/lib/Mojolicious/Plugin/TtRenderer/Engine.pm @@ -85,9 +85,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; @@ -150,6 +153,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} @@ -173,6 +177,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 index 4ddac7a..7f5ca9b 100644 --- a/t/default_template.t +++ b/t/default_template.t @@ -28,7 +28,7 @@ my $t = Test::Mojo->new; $t->get_ok('/') ->status_is(500) - ->content_isnt(''); + ->content_like(qr{foo}); __DATA__