Skip to content

Parent context in an ifCond in a each is wrong #539

Description

@hifi-phil

When using parent context in a ifCond in an each then data scope is different to what happens in handlebars js

The scope of ../this should be the root where as ../../this points to the root

Test to reproduce

[Fact]publicvoidwith_an_ifCond_in_a_loop_then_the_parent_this_context_in_the_ifCond_should_be_the_root(){varsource=@"{{#each loop}} {{#ifCond another '===' 'value'}} test {{{../this.foo}}} {{/ifCond}} {{/each}}";varpartialSource="test {{foo}}";vartemplate=HandlebarsDotNet.Handlebars.Compile(source);using(varreader=newStringReader(partialSource)){varpartialTemplate=HandlebarsDotNet.Handlebars.Compile(reader);HandlebarsDotNet.Handlebars.RegisterTemplate("partial",partialTemplate);}HandlebarsDotNet.Handlebars.RegisterHelper("ifCond",(writer,options,context,parameters)=>{if(parameters.Length!=3)options.Inverse(writer,context);else{if(parameters[0]==parameters[2])options.Template(writer,context);elseoptions.Inverse(writer,context);}});vardata=new{foo="bar",loop=newobject[]{new{another="value"}}};varoutput=template(data);Assert.Equal(output,"test bar");}

Has anyone else had this issue? I'm happy to work on a pull request but don't know where to start

Activity

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