0

I have an express application that uses handlebars as view template engine.

I have a page that is written as a handlebars template. The problem is that part of this page must be rendered by the server, and other parts must be rendered on the client.

<body>
    <div>my page with handlebars {{me}}</div>
    <script id="each-template" type="text/x-handlebars-template" src="/partials/model1.js">
        sample template {{friend}}
    </script>
</body>

The problem is that the page gets to the client fully rendered (including the template within ).

<body>
    <div>my page with handlebars Patricio</div>
    <script id="each-template" type="text/x-handlebars-template" src="/partials/model1.js">
        sample template 
    </script>
</body>

But it should be:

<body>
<div>my page with handlebars Patricio</div>
<script id="each-template" type="text/x-handlebars-template" src="/partials/model1.js">
    sample template {{friend}}
</script>

How can get this result?

Pato Loco
  • 1,205
  • 1
  • 13
  • 29
  • possible duplicate of [Escape double braces {{ ... }} in Mustache template. (templating a template in NodeJS)](http://stackoverflow.com/questions/13944623/escape-double-braces-in-mustache-template-templating-a-template-in-n) – Ben Fortune Nov 20 '14 at 16:03
  • Also [Render double curly-brackets inside Assemble.io partial](http://stackoverflow.com/questions/22249235/render-double-curly-brackets-inside-assemble-io-partial) – Ben Fortune Nov 20 '14 at 16:03

1 Answers1

0

The fastest and best way to get this done is using pre-compiled handlebars templates:

http://handlebarsjs.com/precompilation.html

and then consuming then using the runtime

http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars.runtime-v2.0.0.js

In this way, there's no markup to be scanned and both, client and server, can use the same pre-compiled template

Pato Loco
  • 1,205
  • 1
  • 13
  • 29