Skip to content

Commit

Permalink
Fix using template parts via render-template
Browse files Browse the repository at this point in the history
The `@*CRO-TEMPLATE-PART-PROVIDERS` dynvar was only set in the `template`
multis. Moving it to `render-internal` should cover all needed code paths.
  • Loading branch information
patrickbkr committed Mar 7, 2024
1 parent 65ef381 commit 68905c3
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/Cro/WebApp/Template.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ multi render-template(Str $template, $initial-topic, :%parts --> Str) is export
}

sub render-internal($compiled-template, $initial-topic, %parts) {
my @*CRO-TEMPLATE-PART-PROVIDERS;
{
CATCH { when X::Cro::HTTP::Router::OnlyInHandler {
# We want to allow `render-template()` and `template()` to work
# outside of a `route()` block. Thus when we're outside, just be ok
# with not finding any template part provider such a block would
# provide.
}}
@*CRO-TEMPLATE-PART-PROVIDERS := router-plugin-get-configs($template-part-plugin, error-sub => 'template');
}
my $*CRO-TEMPLATE-MAIN-PART := $initial-topic;
my %*CRO-TEMPLATE-EXPLICIT-PARTS := %parts;
my %*WARNINGS;
Expand Down Expand Up @@ -185,7 +195,6 @@ sub template-part(Str $name, &provider --> Nil) is export {
#| the response body. The initial topic is passed to the template to render. The
#| content type will default to text/html, but can be set explicitly also.
multi template($template, $initial-topic, :%parts, :$content-type = 'text/html' --> Nil) is export {
my @*CRO-TEMPLATE-PART-PROVIDERS := router-plugin-get-configs($template-part-plugin, error-sub => 'template');
content $content-type, render-template($template, $initial-topic, :%parts);
}

Expand Down

0 comments on commit 68905c3

Please sign in to comment.