Skip to content

^if is not handled as reverse condition #387

Closed

Description

@oformaniuk

Describe the bug

^if is not recognised as a condition expression.
Instead HandlebarsRuntimeException is thrown:

Template references a helper that cannot be resolved. BlockHelper '^if'

Expected behaviour:

^if translates into a reversed condition

Test to reproduce

[Fact]
public void ReverseCondition()
{
    const string template = "{{^if false}}false{{/if}}";

    var handlebars = Handlebars.Create();
    var handlebarsTemplate = handlebars.Compile(template);
    var actual = handlebarsTemplate(null);
    
    Assert.Equal("false", actual);
}

Activity

  1. oformaniuk commented on Nov 12, 2020

    @oformaniuk
    MemberAuthor

    The same is true for ^unless

  2. oformaniuk commented on Nov 12, 2020

    @oformaniuk
    MemberAuthor

    ^each has the same behaviour

  3. oformaniuk commented on Nov 12, 2020

    @oformaniuk
    MemberAuthor

    One of the solutions I see is to treat if, unless and each as a plain block helpers. However in that case we'd need to fix /issues/263 so else X is not broken for if. This path may lead to a performance degradation as all of the above are optimised on Expression Tree level.
    Alternative, and probably simpler, solution is to fix all of the above independently.

  4. added a commit that references this issue on Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions