ericf / express-handlebars

A Handlebars view engine for Express which doesn't suck.
BSD 3-Clause "New" or "Revised" License
2.31k stars 384 forks source link

Shared layout #35

Closed daslicht closed 11 years ago

daslicht commented 11 years ago

Hello, do you please like to explain a bit what is going on here and why: For example what does revive() do ? Thank You very Much !

    <script>
        (function () {
            var revive    = Handlebars.template,
                templates = Handlebars.templates = Handlebars.templates || {};

          {{#templates}}
            templates['{{{name}}}'] = revive({{{template}}});
          {{/templates}}
        }());
    </script>
ericf commented 11 years ago

This is take precompiled Handlebars templates built on the fly on the server, and embedding them into the HTML page. For these precompiled templates to be usable in the browser they must first be "revived" by the Handlebars runtime.

http://handlebarsjs.com/precompilation.html

blowback commented 10 years ago

I had trouble understanding this too; the handlebars ref isn't particularly helpful (at first). As far as I can figure out tho, what's going on here is:

...at least that's what I think is happening!