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

@eq: problem with value=false #85

Closed
whncode opened this issue Jul 17, 2014 · 2 comments · Fixed by #104
Closed

@eq: problem with value=false #85

whncode opened this issue Jul 17, 2014 · 2 comments · Fixed by #104

Comments

@whncode
Copy link

whncode commented Jul 17, 2014

I have data set like that:
[{"val": false}, {"val": true}]

And template:
{#.}
{@eq key=val value=false}
FALSE
{:else}
NULL
{/eq}
{/.}

Value=false is compiled to: "value": ctx.get(["false"], false), not to false. I think is it inncorect. For other base types like integers we get right: "value": 1.

@kate2753
Copy link
Contributor

Any helper parameter that is not surrounded by quotes will be considered a reference. Consider this example:

JSON:

{
  "false":"mypropertyWithNameFalse"
}

and template

{@eq key=false type="string" value="mypropertyWithNameFalse"}
same
{:else}
not same
{/eq}

Dust will grab value of false key from context and as a result will render same.

In order for your example to work you'll need to pass in false in as a string and use type="boolean" parameter on eq helper like so:

{@eq key=val value="false" type="boolean"}

In this case values of key and value parameters will be coerced to boolean type and you'll get the result you are looking for.

Alternatively you could do type="string" to convert and compare values as strings. But there seems to be an issue with coerce not coercing falsy values. I think that's a bug and it needs to be fixed.

@sethkinast
Copy link
Contributor

Unrelated to the problem, but you can write this like:

{#.}
  {^val}
  FALSE
  {:else}
  TRUE
  {/val}
{/.}

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

Successfully merging a pull request may close this issue.

3 participants