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

passing number into helper causes weird behavior #735

Closed
intale opened this issue Feb 12, 2014 · 3 comments
Closed

passing number into helper causes weird behavior #735

intale opened this issue Feb 12, 2014 · 3 comments

Comments

@intale
Copy link

intale commented Feb 12, 2014

Handlebars 1.3.0
I have simple helper:

Handlebars.registerHelper "assertEqual", (value1, value2, block)->
    if value1 is value2
      block.fn(@)
    else
      block.inverse(@)

And the template:

{{#each pages}}
            {{#assertEqual this -1}}
                <span class="b-paginator__gap">
                    ...
                </span>
            {{else}}
                <a class="b-paginator__link {{#assertEqual ../../currentPage this}}b-paginator__current{{/assertEqual}}" href="{{pagePathFor this}}">
                    {{this}}
                </a>
            {{/assertEqual}}
        {{/each}}

The line of interest is:

  assertEqual ../../currentPage this

For some reason, instead of normal integer value this statement ../../currentPage shows next(when console.log it):

Number { _dateElement="day", fromNow=function(), ago=function(), ещё...}

So, for example, assertEqual this ../../currentPage when currentPage is 1 and this is 1, returns false.
But when just insert it as a text, e.g.

<a data-current="{{../../currentPage}}"></a>

it is shown as expected - as a normal integer number.

One more inportrant thing - I am using RoR with assets precompilation. So in development mode, where assets precompilation is disable - the issue doesn't present. But after precompilation I have it...

Any ideas?

@intale
Copy link
Author

intale commented Feb 12, 2014

Ok. After some inspection, it looks like that the problem in "each" helper. It returns instance of Number instead of returning regular integer value.
Also, I temporary solved a pb writing new helper to compare numbers, and original problem remains unresolved...

@kpdecker
Copy link
Collaborator

I'm not sure what you mean by instanceof Number can you create a jsfiddle demonstrating your issue? http://jsfiddle.net/9D88g/11/ can be used as a template.

@kpdecker
Copy link
Collaborator

kpdecker commented Mar 6, 2014

Closing as I don't have a repo case, but glad to reopen if one is posted.

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