danharper / Handlebars-Helpers

A small collection of useful helpers for Handlebars.js
Do What The F*ck You Want To Public License
273 stars 55 forks source link

Greater than always returning true #9

Closed nodesocket closed 11 years ago

nodesocket commented 11 years ago

I am using a simple greater than if statement:

{{#if_gt total_transactions compare="10"}}
    <p>In here</p>
{{/if_gt}}

But I am always getting into the if statement, even though total_transactions is less than 10.

Any ideas?

danharper commented 11 years ago

Are you sure? Here's a JSFiddle with it working: http://jsfiddle.net/VzkRs/1/

Perhaps you need to upgrade the library?

nodesocket commented 11 years ago

I am using:

DEBUG: ------------------------------- lib-dev.js:10269
DEBUG: Ember.VERSION : 1.0.0-rc.3 lib-dev.js:10269
DEBUG: Handlebars.VERSION : 1.0.0-rc.3 lib-dev.js:10269
DEBUG: jQuery.VERSION : 1.9.1 lib-dev.js:10269
DEBUG: -------------------------------

Still seeing this bug. If I simply hard code:

 {{#if_gt 5 compare="10"}}
     ...
 {{/if_gt}}

That works. Could it be related to the fact that we are using the following structure:

//total_transactions length is 5

{{#each transaction in transactions }}
    ...
{{else}}
    ...
{{/each}}
{{#if_gt total_transactions compare="10"}}
   ...
{{/if_gt}}

Still getting into the if_gt block.

danharper commented 11 years ago

Is total_transactions a number? Is it definitely what it appears to be?

eg. create a log helper:

Handlebars.registerHelper('log', function(input) { console.log(input); });

And then {{log total_transactions}} where you need it.

nodesocket commented 11 years ago

Just confirmed, it is undefined. Darn this is a problem.

What might be happening is when the template is rendered total_transactions is undefined, it is being set in the model with:

reopenClass({ })

Is there a work around for this?

danharper commented 11 years ago

reopenClass is an Ember method, right? I don't have any experience with it, so I couldn't say. I'm not sure if Ember somehow uses Handlebars differently?

Sorry I can't be of any more help.