Skip to content

Instantly share code, notes, and snippets.

@ppcano
Created September 11, 2012 10:35
Show Gist options
  • Select an option

  • Save ppcano/3697504 to your computer and use it in GitHub Desktop.

Select an option

Save ppcano/3697504 to your computer and use it in GitHub Desktop.
Handlebar helper to comparte ember objects
var getBindingValue = function(context, options, path) {
var normalized = Ember.Handlebars.normalizePath(null, path, options.data),
thisContext;
if (normalized.isKeyword) {
thisContext = normalized.root;
} else if (!Ember.isGlobalPath(path)) {
thisContext = context;
} else {
thisContext = null;
}
return Em.Handlebars.getPath(thisContext, normalized.path);
};
Handlebars.registerHelper('if_eq', function(context, options) {
var values = context.split(' '),
value = getBindingValue(this, options, values[0]),
expected = getBindingValue(this, options, values[1]);
return (value === expected) ? options.fn(this) : options.inverse(this);
});
Handlebars.registerHelper('unless_eq', function(context, options) {
var values = context.split(' '),
value = getBindingValue(this, options, values[0]),
expected = getBindingValue(this, options, values[1]);
return (value !== expected) ? options.fn(this) : options.inverse(this);
});
{{#each activities}}
{{#if_eq "user view.loggedUser"}}
activity user is equal than loggedUser
{{ else }}
is not the same user
{{/if_eq}}
{{/each}}
@escalant3

Copy link
Copy Markdown

Could you please provide a jsfiddle with actual data to follow the code easily?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment