神刀安全网

Build your stack with Handlebars.js for create static pages.

tiny-compilator

Build your stack with Handlebars.js for create static pages. It must be useful with Express.js for return the html view after a http request.

How to install

npm install tiny-compilator 

How it works

Create a Compilator instance with in arguments the paths of layouts, helpers & partials folders. Then call render method of your instance with the path of your page and datas to pass:

var Compilator = require('tiny-compilator');  var compile = new Compilator({   helpers: 'path/to/helper/folder',   layouts: 'path/to/layout/folder',   partials: 'path/to/partials/folder' });  compile.render('path/to/your/page', ObjectDatas); //=> return html compiled

Page configuration

In top of your page you must declare in attribute the layout chosen as this example:

--- layout: 'default' --- <!-- html page -->

Layout declaration

In your layout html you must call the partial handlebars ‘body’ where all the page content must be placed:

<!DOCTYPE html> <html>   <head>     <meta charset="utf-8">     <title></title>   </head>   <body>     {{> body }}   </body> </html>

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » Build your stack with Handlebars.js for create static pages.

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址