ghempton
ghempton

Reputation: 7947

Ember.js Strip Binding Tags

Is there a way to strip binding tags from an ember.js infused handlebars template? I would like to be able to extract just the html without any of the metamorph script tags.

I have this related question but wanted to ask this more general question as well.

Upvotes: 4

Views: 1900

Answers (3)

Denzo
Denzo

Reputation: 431

Here's a better way

{{unbound propertyName}}

http://emberjs.com/api/classes/Ember.Handlebars.helpers.html#method_unbound

Upvotes: 3

ebryn
ebryn

Reputation: 4407

You can use the unbound Handlebars helper to do this at the individual property level.

There is work being done on an #unbound block helper, which would be nice for what you're trying to do: https://github.com/emberjs/ember.js/pull/321

Another approach is to, in your views, specify a plain Handlebars template. None of the output will be bound.

App.UnboundView = Ember.View.extend({
  template: Handlebars.compile("output is: {{msg}} here"),
  msg: "not bound"
});

Here's a jsFiddle example: http://jsfiddle.net/ebryn/zQA4H/

Upvotes: 7

ghempton
ghempton

Reputation: 7947

In case anyone needs this functionality, I created a small jquery plugin to do it:

# Small extension to create a clone of the element without
# metamorph binding tags and ember metadata

$.fn.extend
  safeClone: ->
    clone = $(@).clone()

    # remove content bindings
    clone.find('script[id^=metamorph]').remove()

    # remove attr bindings
    clone.find('*').each ->
      $this = $(@)
      $.each $this[0].attributes, (index, attr) ->
        return if attr.name.indexOf('data-bindattr') == -1
        $this.removeAttr(attr.name)

    # remove ember IDs
    clone.find('[id^=ember]').removeAttr('id')
    clone

Still hoping there is a better way.

Upvotes: 2

Related Questions