# Capturing a handlebars template as a string

**URL:** <https://discuss.emberjs.com/t/capturing-a-handlebars-template-as-a-string/5262>\
**Category:** Uncategorized\
**Created:** [May 14, 2014, 3:48pm UTC](https://discuss.emberjs.com/t/capturing-a-handlebars-template-as-a-string/5262 "2014-05-14T15:48:03Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![droberts](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/droberts/32/15689_2.png) [@droberts](https://discuss.emberjs.com/u/droberts)\
**Post date:** [May 14, 2014, 3:48pm UTC](https://discuss.emberjs.com/t/capturing-a-handlebars-template-as-a-string/5262/1 "2014-05-14T15:48:03Z")

</div>

I have a template that I’d like to capture its output as a string that I can store on a model. For example:

I’m using Ember Rails, so I don’t have the script tag

in app/assets/javascripts/templates/person\_as\_xml.handlebars

```
<person>
  <name>{{name}}</name>
  <children>
  {{#each children}}
    <kid><name>{{name}}</name></kid>
  {{/each}}
  </children>
</person>

```

Then I want to, perhaps in an action:

```
actions: {
  save: function(person){
    person.xml_representation = Handlebars.render_template("person_as_xml.handlebars", person);
    person.save();
  }
}

```

Obviouisly I made up the syntax for render\_template, but that’s essentially what I want to do. How can I do it?
