Mike Aski
Mike Aski

Reputation: 9236

Whitespace in an identifier used from an handlebars template

It is possible to have whitespace in an Ember.Object's field name, but how to render its value?

The following JSFiddle illustrates my aim: http://jsfiddle.net/MikeAski/aTpz4/

Any idea?

Upvotes: 1

Views: 624

Answers (1)

pangratz
pangratz

Reputation: 16163

I think this is not possible, since for Handlebars it looks like you want to use a helper named my.

Also in your example an error Uncaught Error: Handlebars error: Could not find property 'my' on object <.MyView:ember147> is thrown.

You could write your own Handlebars helper, see http://jsfiddle.net/pangratz666/KAsNN/

Handlebars:

<script type="text/x-handlebars" data-template-name="my-template">
    This does work: {{echo "myField"}}
    This does work: {{echo "my field"}}
</script>

JavaScript:​

Ember.Handlebars.registerHelper('echo', function(propertyName, options) {
    return Ember.getPath(options.contexts[0], propertyName);
});

The helper above is not bindings aware. There is a Pull Request for this: https://github.com/emberjs/ember.js/pull/615

Upvotes: 1

Related Questions