Skip to content

Commit 9e40ccd

Browse files
committed
feat: Support for parameters in partials
1 parent b900023 commit 9e40ccd

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

libs/FuManchu/Renderer/PartialBlockRenderer.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace FuManchu.Renderer;
55

66
using System.Collections.Generic;
7+
using System.Dynamic;
78
using System.IO;
89
using System.Linq;
910

@@ -40,6 +41,13 @@ protected override void Render(Block block, Arguments? arguments, Map? maps, Ren
4041
Write(scope.ScopeContext, writer, new SafeString(context.Service.RunPartial(name, scope.ScopeContext)));
4142
}
4243
}
44+
else if (maps is { Count: > 0 })
45+
{
46+
using (var scope = context.BeginScope(maps))
47+
{
48+
Write(scope.ScopeContext, writer, new SafeString(context.Service.RunPartial(name, scope.ScopeContext)));
49+
}
50+
}
4351
else
4452
{
4553
Write(context, writer, new SafeString(context.Service.RunPartial(name, context)));

tests/FuManchu.Tests/Renderer/PartialBlockRendererFacts.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,15 @@ public void CanRenderPartialWithChildModel()
3939

4040
RenderTest(template, expected, new { person = new { forename = "Matthew", surname = "Abbott" } });
4141
}
42+
43+
[Fact]
44+
public void CanRenderPartialWithArguments()
45+
{
46+
HandlebarsService.RegisterPartial("body", "{{firstName}} {{lastName}}");
47+
48+
string template = "{{>body firstName=person.forename lastName=person.surname}}";
49+
string expected = "Matthew Abbott";
50+
51+
RenderTest(template, expected, new { person = new { forename = "Matthew", surname = "Abbott" } });
52+
}
4253
}

0 commit comments

Comments
 (0)