Code Monkey home page Code Monkey logo

Comments (2)

ericf avatar ericf commented on July 29, 2024

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

from express-handlebars.

blowback avatar blowback commented on July 29, 2024

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:

  • when this template is parsed server side, the example exposeTemplates middleware inserts the shared templates (from partialsDir) in a local called 'templates' an array where each member has a name and template content
  • the above snippet is parsed server side; {{#templates}} is undocumented shorthand for {{#each templates}}
  • inside the #each loop, this snippet is inserting the templates into the client-side Handlebars.templates (ie it's doing the same job as the handlebars precompiler)
  • when the code hits client-side, your precompiled templates are now in Handlebars.templates.*, you can use them with the reduced runtime exactly like regular precompiled templates.

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

from express-handlebars.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.