Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,21 @@ var result = template(data);
*/
```

Partials, including inline partials declared with `{{#*inline}}`, accept hash arguments at the call site. The hash values are merged into the partial's context alongside any properties inherited from the calling context:

```c#
string source =
@"{{#*inline ""user""}}<strong>{{name}}</strong>{{/inline}}{{> user name=""Karen""}}";

var template = Handlebars.Compile(source);

var result = template(null);

/* Would render:
<strong>Karen</strong>
*/
```

### Registering Helpers

```c#
Expand Down
23 changes: 23 additions & 0 deletions source/Handlebars.Test/InlinePartialTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,29 @@ public void BasicInlinePartialWithIncompleteChildContextDoesNotFallback()
Assert.Equal("Hello, Marc !", result);
}

[Fact]
public void InlinePartialDefinitionWithExtraArgumentDoesNotThrow()
{
// Regression test for https://github.com/Handlebars-Net/Handlebars.Net/issues/560
string source = "{{#*inline \"my_partial\" arg}}{{arg}}{{/inline}}{{>my_partial}}";

var template = Handlebars.Compile(source);
var result = template(null);

Assert.Equal(string.Empty, result);
}

[Fact]
public void InlinePartialDefinitionWithHashArgumentDoesNotThrow()
{
string source = "{{#*inline \"my_partial\" arg=5}}{{arg}}{{/inline}}{{>my_partial}}";

var template = Handlebars.Compile(source);
var result = template(null);

Assert.Equal(string.Empty, result);
}

[Fact]
public void BasicBlockInlinePartial()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ internal sealed class InlineBlockDecoratorDescriptor : IDecoratorDescriptor<Bloc
{
public TemplateDelegate Invoke(in TemplateDelegate function, in BlockDecoratorOptions options, in Context context, in Arguments arguments)
{
if (arguments.Length != 1)
if (arguments.Length == 0)
{
throw new HandlebarsRuntimeException("{{*inline}} helper must have exactly one argument");
throw new HandlebarsRuntimeException("{{*inline}} helper must have at least one argument");
}

var bindingContext = options.Frame;
Expand Down
Loading