Skip to content
New issue

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

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

Already on GitHub? # to your account

"each" and custom helper with "else" -- #is ../ #else is ../../? #1204

Closed
jsm174 opened this issue Mar 29, 2016 · 2 comments
Closed

"each" and custom helper with "else" -- #is ../ #else is ../../? #1204

jsm174 opened this issue Mar 29, 2016 · 2 comments

Comments

@jsm174
Copy link

jsm174 commented Mar 29, 2016

Sorry if the title is confusing, but I'm seeing strange behavior when trying to compare a value using a custom helper in an "else" wrapped in an "each":

Given the following:

JSON:

{
   "list": {
      "style": "unordered",
      "items": [
         "value1",
         "value2",
         "value3"
      ]
   }
}

PARTIAL:

<script id="partial-text-list" type="text/x-handlebars-template">
   {{#each items}}
      {{#is ../style "ordered"}}
         {{inc @index}} {{this}}
      {{else is ../style "unordered"}}
         - {{this}}
      {{/is}}
   {{/each}}
</script>

HELPER:

Handlebars.registerHelper({
   is: function(value, test, options) {
      if (value === test) {
         return options.fn(this);
      }
      else {
         return options.inverse(this);
      }
    }
});

ISSUE:

The correct value of "style" is passed to the first "is" helper call, but not to the "else is" helper call.

If I change the partial to:

{{#is ../style "ordered"}}
   {{inc @index}} {{this}}
{{else is ../../style "unordered"}}
   - {{this}}
{{/is}}

the correct value of style is passed to the "else is".

Is this expected behavior, and if so why, because I'm not following "../../"?

@jsm174 jsm174 changed the title Issue with "each" and custom helper with "else" -- #is ../ #else is ../../? "each" and custom helper with "else" -- #is ../ #else is ../../? Mar 29, 2016
@rafde
Copy link

rafde commented Aug 25, 2016

@jsm174 {{else is}} wont work. you might be able to do something like
{{else if (is ../style "unordered")}} if you can figure out the logic allow your block helper to support also being a helper.

Here's an example gist of a helper I made

https://gist.github.com/rafde/61ffde650f392d26c91f533115f92ec1

@jsm174
Copy link
Author

jsm174 commented Aug 30, 2017

I know this issue is quite old but I just updated our application from v4.0.5 to v4.0.10 and it is now working as expected.

I downloaded the closest build to v4.0.6 at: http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-714a4c4.js

(For some reason I couldn't find a v4.0.6 or v4.0.7 files)

Anyway, that version worked, so I'm guessing this issue was fixed as a result of: #1135

@jsm174 jsm174 closed this as completed Aug 30, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants