tpl_apply

2019-02-14 admin

tpl_apply是什么

什么是tpl_apply,tpl_apply with handlebars

tpl_apply使用教程帮助文档

tpl_apply

tpl_apply with handlebars

npm version

Install

npm install --save tpl_apply

Test

npm test

Usage

方式1 :basic

var tpl = require('./index');

var source = process.cwd() + '/tpl.js'
var dest = process.cwd() + '/test/tpl.generate.js'

tpl.tpl_apply(source, {
	title: "My New Post", body: "This is my first post!"
}, dest);

方式2 :with helpers

source = process.cwd() + '/tpl2.js'
dest = process.cwd() + '/test/tpl2.generate.js'

var Handlebars = require('handlebars');

Handlebars.registerHelper('list', function(items, options) {
  var out = "<ul>";

  for(var i=0, l=items.length; i<l; i++) {
    out = out + "<li>" + options.fn(items[i]) + "</li>";
  }

  return out + "</ul>";
});

tpl.tpl_apply_with_register_helper(Handlebars, source, {
  people: [
   {firstName: "Yehuda", lastName: "Katz"},
   {firstName: "Carl", lastName: "Lerche"},
   {firstName: "Alan", lastName: "Johnson"}
 ]
}, dest);

本站文章除注明转载外,均为本站原创或编译。欢迎任何形式的转载,但请务必注明出处。

转载请注明:文章转载自 JavaScript中文网 [https://www.javascriptcn.com]

本文地址:https://www.javascriptcn.com/read-53732.html

文章标题:tpl_apply

回到顶部