4

I'd like to get the un-altered/un-rendered/whatever content of a block in handlebars. So, let's say I've got the following:

{{#template}}
    <tr><td>{{name}}</td><td>{{price}}</td></tr>
{{/template}}

If I've got a helper called 'template', I'd like to be able to reference the original content block - not the 'compiled' template block. So, I'd like to be able to get the string of <tr><td>{{name}}</td><td>{{price}}</td></tr> without the {{name}} and {{price}} being 'rendered'.

Right now, it looks like the only thing I have access to is 'this.options.fn', which seems to be just a precompiled template piece.

Is there any way to accomplish this? So far all I'm seeing is references to the compiled content.

Note - if there's even a way to just say "I literally want this printed out", that would work just fine as well. For example, {literal} in Smarty, which will ignore everything until {/literal}.

Stephen
  • 5,362
  • 1
  • 22
  • 33
  • 1
    I don't know what your overall intent is but couldn't you use partials instead of trying to manipulate template fragments directly? – mu is too short Nov 28 '12 at 16:56
  • The intent is mostly just for literal "this is what I want to be in the HTML". There are various reasons - documentation, not having to require five separate three line html files for template snippets.. things like that. Partials aren't quite what I need in this case (though I do use them and know how to use them). – Stephen Nov 29 '12 at 00:50
  • I had the exact same need, too bad there doesn't seem to be a solution. – AlexG Dec 13 '12 at 10:31
  • There's a closed issue, if you can follow the proposed solution : https://github.com/wycats/handlebars.js/issues/353 – mghicks Dec 14 '12 at 07:31

1 Answers1

1
<script type="text/template" id="my-template">
  <tr><td>{{name}}</td><td>{{price}}</td></tr>  
</script>

var uncompiledTemplate = $( '#my-template');
jthiesse
  • 342
  • 2
  • 4