About
Simple handlebars processor that supports multiple templates per file <script id="template_name" type="test/html">....</script>
.
Install
npm install hbsp
Usage
Promise style, for pure js, async/await like coding style.
const fs = ;const hbsPrecompile = precompile; const readFile = ; ;
File Examples
single.hbs
Hello {{name}}
multiple.hbs
When including the templates.js you will get the following variables set as handlebars precompiled function:
Handlebarstemplates'single'Handlebarstemplates'ProjectListNav'Handlebarstemplates'ProjectListNav-list'
Typically we have the following javascript before the templates.js
1_render.js
// --------- Render --------- //// Just a little indirection to render a template using handlebars.// This simple indirection allows much flexibility later one, // when using pre-compiling or other templating engine are needed. // The node.js hbsp process will put the precompile function in the Handlebars.templatesHandlebarstemplates = Handlebarstemplates || {}; ; // Global scope is acceptable for this very generic function (could be namespaced if it is the developer preference){ var tmpl = HandlebarstemplatestemplateName; // if not found, try to get it from the DOM and assume the full handlebars if !tmpl var html = ; if !html throw "Not template found in pre-compiled and in DOM for " + templateName; tmpl = Handlebars; HandlebarstemplatestemplateName = tmpl; // call the function and return the result return ;}// --------- /Render --------- //