mardi 28 juillet 2015

Is it possible to know the scope in which my helper is called without passing a parameter

I got the following helper :

import Ember from 'ember';
import ENV from '../config/environment';

export default Ember.Handlebars.makeBoundHelper( function(property, object) {
    for (var attribute in object) {
        if (attribute.indexOf("translations") > -1) {
            var translations = object.get(attribute).filterBy('locale', ENV.LOCALE);
            return translations.get('firstObject.' + property);
        }   
    }

    console.log('Trying to find property ' + property + ' on object: ');
    console.log(object);

    return false;
});

Basically I have some models that can be translated (ie name of a product). Depending on the user selected locale it will show the translation of a given property. I think it's super sexy and gives a very good feel to the user.

However, I always end up calling my helper this way :

{{ translate 'name' this }}

Is there a way that I wouldn't need to include "this" each time I call my helper and get the current scope from within my helper?




Aucun commentaire:

Enregistrer un commentaire