You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
Activity
rexm commentedon 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 commentedon Feb 18, 2019
Cool thanks,
Turns out this syntax applies to the JS parser:
handlebars-lang/handlebars.js#608
tyriker commentedon Jan 21, 2025
@rexm do you mean
includeZero=trueas being an arbitrary statement? TheincludeZerooption has been a part of the#ifhelper since roughly 2014. https://handlebarsjs.com/guide/builtin-helpers.html#ifShould Handlebars.NET support this option? I expected it to work and saw the same result.
I believe the exception comes from here
Handlebars.Net/source/Handlebars/Compiler/Lexer/Converter/BlockAccumulators/ConditionalBlockAccumulatorContext.cs
Line 33 in 9cf1672
I have forked the repo to take a closer look, but can't promise anything and may opt for a workaround as it relates to my current needs.
rexm commentedon Jan 21, 2025
I think I misunderstood what was originally being asked. I don’t think it would be terribly hard to extend the parser to handle this grammar.
fix: support includeZero=true on #if helper (issue #285)
Merge pull request #639 from Handlebars-Net/fix/issue-285