Skip to content

"An item with the same key has already been added" when using inline partial to pass data to partial #306

Closed

Description

@johnknoop

I'm trying to render this template:

{{#>my-layout}}
{{#*inline "title"}}My title{{/inline}}
	Some page content
{{/my-layout}}

This is the content of my-layout:

<html>
<head>
	<title>{{>title}}</title>
</head>
<body>
	{{>@partial-block}}
</body>
</html>

Exception:

Runtime error while rendering partial 'my-layout', see inner exception for more information

Inner exception:

An item with the same key has already been added. Key: title

Stack trace:

   at HandlebarsDotNet.Compiler.PartialBinder.InvokePartial(String partialName, BindingContext context, HandlebarsConfiguration configuration)
   at HandlebarsDotNet.Compiler.PartialBinder.InvokePartialWithFallback(String partialName, BindingContext context, HandlebarsConfiguration configuration)
   at HandlebarsDotNet.Handlebars.HandlebarsEnvironment.<>c__DisplayClass7_0.<Compile>b__0(Object context)

Any ideas?

Activity

  1. johnknoop commented on Jun 22, 2019

    @johnknoop
    Author

    Update:

    It renders if I change the template into this:

    {{#*inline "title"}}My title{{/inline}}
    {{#>my-layout}}
    	Some page content
    {{/my-layout}}

    But it's not actually the same thing, since each inline partial is available to the current block and all children, including execution of other partials so the title partial now becomes available to the whole template, which is good enough for me right now, but not great in general.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions