File tree Expand file tree Collapse file tree 3 files changed +19
-7
lines changed Expand file tree Collapse file tree 3 files changed +19
-7
lines changed Original file line number Diff line number Diff line change @@ -132,13 +132,14 @@ sub render {
132132
133133 # Localize "extends" and "layout" to allow argument overrides
134134 my ($maybe , $ts ) = @{$args }{' mojo.maybe' , ' mojo.string' };
135- my $stash = $self -> stash;
135+ my $stash = $self -> stash;
136+ my $inline = exists $args -> {inline } || exists $stash -> {inline };
136137 local $stash -> {layout } = $stash -> {layout } if exists $stash -> {layout };
137138 local $stash -> {extends } = $stash -> {extends } if exists $stash -> {extends };
138139
139- # Rendering to string
140+ # Rendering to string or using inline templates
140141 local @{$stash }{keys %$args } if $ts || $maybe ;
141- delete @{$stash }{qw( layout extends) } if $ts ;
142+ delete @{$stash }{qw( layout extends) } if $ts || $inline ;
142143
143144 # All other arguments just become part of the stash
144145 @$stash {keys %$args } = values %$args ;
Original file line number Diff line number Diff line change @@ -525,8 +525,9 @@ To set a C<layout> stash value application-wide you can use L<Mojolicious/"defau
525525
526526 $app->defaults(layout => 'mylayout');
527527
528- Layouts can also be used with L<Mojolicious::Controller/"render_to_string">, but the C<layout> value needs to be passed
529- as a render argument (not a stash value).
528+ Layouts can also be used with L<Mojolicious::Controller/"render_to_string">, or when rendering
529+ L<inline templates|/"Rendering inline templates">, but the C<layout> value needs to be passed as a render argument
530+ (not a stash value).
530531
531532 my $html = $c->render_to_string('reminder', layout => 'mail');
532533
Original file line number Diff line number Diff line change @@ -97,6 +97,11 @@ get '/content_with';
9797
9898get ' /inline' => {inline => ' <%= "inline!" %>' };
9999
100+ get ' /inline/explicit_layout' => sub {
101+ my $c = shift ;
102+ $c -> render(inline => ' <%= "inline!" %>' , layout => ' layout' );
103+ };
104+
100105get ' /inline/again' => {inline => 0};
101106
102107get ' /data' => {data => 0};
@@ -251,11 +256,16 @@ subtest 'Content blocks' => sub {
251256};
252257
253258subtest ' Inline template' => sub {
254- $t -> get_ok(' /inline' )-> status_is(200)-> header_is(Server => ' Mojolicious (Perl)' )-> content_is(" Defaultinline!\n\n " );
259+ $t -> get_ok(' /inline' )-> status_is(200)-> header_is(Server => ' Mojolicious (Perl)' )-> content_is(" inline!\n " );
260+ };
261+
262+ subtest ' Inline with layout' => sub {
263+ $t -> get_ok(' /inline/explicit_layout' )-> status_is(200)-> header_is(Server => ' Mojolicious (Perl)' )
264+ -> content_is(" layouted inline!\n\n " );
255265};
256266
257267subtest ' "0" inline template' => sub {
258- $t -> get_ok(' /inline/again' )-> status_is(200)-> header_is(Server => ' Mojolicious (Perl)' )-> content_is(" Default0 \n \n" );
268+ $t -> get_ok(' /inline/again' )-> status_is(200)-> header_is(Server => ' Mojolicious (Perl)' )-> content_is(" 0 \n " );
259269};
260270
261271subtest ' "0" data' => sub {
You can’t perform that action at this time.
0 commit comments