Whitespace in an identifier used from an handlebars template

Go To StackoverFlow.com

1

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?

2012-04-05 14:41
by Mike Aski


1

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

2012-04-05 14:52
by pangratz
Thanks a lot for the idea! This will provide a way out of my problem - Mike Aski 2012-04-05 14:54
Glad I could help - pangratz 2012-04-05 14:54
Ads