mustache-sharp icon indicating copy to clipboard operation
mustache-sharp copied to clipboard

JToken

Open oscaruribe opened this issue 7 years ago • 1 comments

When passing dynamically parsed data from Newtonsoft (JToken) all values are IEnumerable but .Any() returns false for non-arrays so all #if tests fail.

Say the template looks like this:

{{#if SomeTest }} Value if true or non-empty {{/if}}

And the dynamic data passed is parsed from JSON as

{ "SomeTest": true } or { "SomeTest": "true" }

In both cases the following line in ConditionTagDefinition.isConditionSatisfied:

IEnumerable enumerable = condition as IEnumerable;

will return an enumerable no matter what the JToken holds as value. Then the following lines:

if (enumerable != null) { return enumerable.Cast<object>().Any(); }

Will return false.

Any ideas?

oscaruribe avatar Jul 10 '17 10:07 oscaruribe

I found a temporary fix to this. If you set your JSON Property to be as follows:

{"SomeTest" : { "anyString" : true } }

The if/else logic will work.

Since this is an ugly fix, let me know if anyone has any better fixes.

Kiran-Bhatia avatar Jul 06 '18 05:07 Kiran-Bhatia