Client-side templates when using Handlebars on the server
If you’re using Handlebars on the client and the server, you’ll run into this issue where the client-side templates will be parsed by the view engine on the server. For example, you may have a file like this:
<h1>My Page Title</h1>
<!-- This template should be transformed into HTML by the server -->
<div id="photoList" class="pure-g">
{{#each photos}}
<div class="photo pure-u-1-12" data-photo-id="{{id}}">
<img class="pure-u-1" src="{{src}}">
</div>
{{/each}}
</div>
<!-- This template should not be touched. It's for the client -->
<script type="text/x-handlebars" id="lightbox-template">
<img class="lightbox-image" src="{{large}}">
<div class="lightbox-meta">
<a class="pure-button lightbox-link" href="{{url}}">View on Flickr</a>
<button class="pure-button lightbox-link lightbox-hide">Hide</button>
</div>
</script>
When you view this on the browser, the tags ({{..}}) within will be parsed out. You’ll get something like this, which is useless:
<!-- I can't use this template on the client anymore!! -->
<script type="text/x-handlebars" id="lightbox-template">
<img class="lightbox-image" src="">
<div class="lightbox-meta">
<a class="pure-button lightbox-link" href="">View on Flickr</a>
<button class="pure-button lightbox-link lightbox-hide">Hide</button>
</div>
</script>
Fortunately, the fix for this is very simple, albeit not documented anywhere. Just add a \ in front of all the opening tags ({{). The \ will be parsed out during the compilation step, and you’ll have a perfectly usable template on the client.
<!-- Add a \ before the handlebars -->
<script type="text/x-handlebars" id="lightbox-template">
<img class="lightbox-image" src="\{{large}}">
<div class="lightbox-meta">
<a class="pure-button lightbox-link" href="\{{url}}">View on Flickr</a>
<button class="pure-button lightbox-link lightbox-hide">Hide</button>
</div>
</script>
Source: link