Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to treat 0 as truthy #285

Closed
sellomkantjwa opened this issue Feb 18, 2019 · 2 comments
Closed

How to treat 0 as truthy #285

sellomkantjwa opened this issue Feb 18, 2019 · 2 comments

Comments

@sellomkantjwa
Copy link

I tried using

testing Var: 
{{#if var includeZero=true}}
    var is set to {{var}}
{{/if}}

but I get

Unhandled Exception: System.InvalidOperationException: Sequence contains more than one element
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at HandlebarsDotNet.Compiler.ConditionalBlockAccumulatorContext..ctor(Expression startingNode)
   at HandlebarsDotNet.Compiler.BlockAccumulatorContext.Create(Expression item, HandlebarsConfiguration configuration)
   at HandlebarsDotNet.Compiler.BlockAccumulator.ConvertTokens(IEnumerable`1 sequence)+MoveNext()
   at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at HandlebarsDotNet.Compiler.ExpressionBuilder.ConvertTokensToExpressions(IEnumerable`1 tokens)
   at HandlebarsDotNet.Compiler.HandlebarsCompiler.Compile(TextReader source)
   at HandlebarsDotNet.Handlebars.HandlebarsEnvironment.Compile(String template)

@rexm
Copy link
Member

rexm commented Feb 18, 2019

Handlebars doesn’t support arbitrary statements.

You could try an inverted #if helper like #not to test the value of var negatively.

@sellomkantjwa
Copy link
Author

Cool thanks,
Turns out this syntax applies to the JS parser:
handlebars-lang/handlebars.js#608

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants