Skip to content

Commit ff4d523

Browse files
committed
fix: Allow indexable objects to be root of expression
1 parent b1cb113 commit ff4d523

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

libs/FuManchu/Binding/TemplateDataEvaluator.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,22 @@ private static IEnumerable<ExpressionPair> GetRightToLeftExpressions(string expr
7676

7777
if (dict != null)
7878
{
79-
success = dict.TryGetValue(key, out value);
79+
string lookupKey = key;
80+
var periodIndex = key.IndexOf('.');
81+
if (periodIndex > -1)
82+
{
83+
lookupKey = key.Substring(0, periodIndex);
84+
key = key.Substring(periodIndex + 1);
85+
}
86+
87+
success = dict.TryGetValue(lookupKey, out value);
88+
if (success)
89+
{
90+
if (key.Length > 0)
91+
{
92+
return EvalComplexExpression(value!, key);
93+
}
94+
}
8095
}
8196
else if (indexableObject != null)
8297
{

tests/FuManchu.Tests/Renderer/PartialBlockRendererFacts.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,15 @@ public void CanRenderPartialWithArguments()
5050

5151
RenderTest(template, expected, new { person = new { forename = "Matthew", surname = "Abbott" } });
5252
}
53+
54+
[Fact]
55+
public void CanRenderPartialWithArguments_UsingNestedValue()
56+
{
57+
HandlebarsService.RegisterPartial("body", "{{person.forename}} {{person.surname}}");
58+
59+
string template = "{{>body person=person}}";
60+
string expected = "Matthew Abbott";
61+
62+
RenderTest(template, expected, new { person = new { forename = "Matthew", surname = "Abbott" } });
63+
}
5364
}

0 commit comments

Comments
 (0)