Skip to content

Very weird behavior inside of a partial with an #each after passing in a custom context to that partial #432

Closed
dotnet/arcade
#16884

Description

@HandleBarsNetQuestion

In the below code, the value of actual1 is "," and the value of actual2 is ",False,I shouldn't show up!,"

I expected the partial "displayList" to have a new context, which would be null since "TheList" is never assigned. I expected the #each to not iterate through anything.

Test to reproduce

        private class ClassWithAList
        {
            public IEnumerable<string> TheList { get; set; }
        }

        private class ClassWithAListAndOtherMembers
        {
            public IEnumerable<string> TheList { get; set; }
            public bool SomeBool { get; set; }
            public string SomeString { get; set; } = "I shouldn't show up!";
        }

        [Fact]
        public void WeirdBehaviour()
        {
            var handlebars = Handlebars.Create();
            handlebars.RegisterTemplate("displayListItem", "{{this}},");
            handlebars.RegisterTemplate("displayList", "{{#each this}}{{> displayListItem}}{{/each}}");
            
            var template = handlebars.Compile("{{> displayList TheList}}");
            var actual1 = template(new ClassWithAList());
            var actual2 = template(new ClassWithAListAndOtherMembers());
            var expected = "";

            Assert.Equal(expected, actual1);
            Assert.Equal(expected, actual2);
        }
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