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

Is there anyway to check condition with a variable? #1352

Closed
happyduong opened this issue May 21, 2017 · 1 comment
Closed

Is there anyway to check condition with a variable? #1352

happyduong opened this issue May 21, 2017 · 1 comment

Comments

@happyduong
Copy link

I have a categories array:

"categories": [
    {
      "id": "22",
      "name": "Brands",
      "url": "/brand/"
    },
    {
      "id": "1",
      "name": "Women",
      "url": "/women/"
      }
}

And i have a setting variable:
"category_id": "1"

in HTML:

{{#each categories}}
     {{#if id '==' '1'}}
          <a href="{{url}}">{{name}}</a>
     {{/if}}
{{/each}}

OUTPUT:
<a href="/women/">Women</a>
==> This is correctly output.

BUT WHEN I USING category_id VARIABLE:

{{#each categories}}
     {{#if id '==' category_id}}
          <a href="{{url}}">{{name}}</a>
     {{/if}}
{{/each}}

==> It's not working. :((

So my question is: Is there anyway to check condition with a variable?

@nknapp
Copy link
Collaborator

nknapp commented May 22, 2017

The {{#if}}-helper only checks for truthy values and it takes only one argument. If you want to compare things, you need to register your own helper: Have a look at #206 for examples on how to achieve this.

@nknapp nknapp closed this as completed May 22, 2017
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