File tree Expand file tree Collapse file tree 4 files changed +19
-6
lines changed Expand file tree Collapse file tree 4 files changed +19
-6
lines changed Original file line number Diff line number Diff line change @@ -133,13 +133,14 @@ sub render {
133133
134134 # Localize "extends" and "layout" to allow argument overrides
135135 my ($maybe , $ts ) = @{$args }{' mojo.maybe' , ' mojo.string' };
136- my $stash = $self -> stash;
136+ my $stash = $self -> stash;
137+ my $inline = exists $args -> {inline } || exists $stash -> {inline };
137138 local $stash -> {layout } = $stash -> {layout } if exists $stash -> {layout };
138139 local $stash -> {extends } = $stash -> {extends } if exists $stash -> {extends };
139140
140- # Rendering to string
141+ # Rendering to string or using inline templates
141142 local @{$stash }{keys %$args } if $ts || $maybe ;
142- delete @{$stash }{qw( layout extends) } if $ts ;
143+ delete @{$stash }{qw( layout extends) } if $ts || $inline ;
143144
144145 # All other arguments just become part of the stash
145146 @$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 @@ -108,7 +108,8 @@ sub render {
108108 # Inheritance
109109 my $content = $stash -> {' mojo.content' } //= {};
110110 local $content -> {content } = $output =~ / \S / ? $output : undef if $stash -> {extends } || $stash -> {layout };
111- while ((my $next = _next($stash )) && !defined $inline ) {
111+ delete $options -> {inline };
112+ while ((my $next = _next($stash ))) {
112113 @$options {qw( handler template) } = ($stash -> {handler }, $next );
113114 $options -> {format } = $stash -> {format } || $self -> default_format;
114115 if ($self -> _render_template($c , \my $tmp , $options )) { $output = $tmp }
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};
@@ -254,6 +259,11 @@ subtest 'Inline template' => sub {
254259 $t -> get_ok(' /inline' )-> status_is(200)-> header_is(Server => ' Mojolicious (Perl)' )-> content_is(" inline!\n " );
255260};
256261
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 " );
265+ };
266+
257267subtest ' "0" inline template' => sub {
258268 $t -> get_ok(' /inline/again' )-> status_is(200)-> header_is(Server => ' Mojolicious (Perl)' )-> content_is(" 0\n " );
259269};
You can’t perform that action at this time.
0 commit comments