English | 简体中文

Simple, free, free writing style module

As easy as writing nodejs

In HTML or JavaScript, directly require other modules

...
<?var dateFormatter = require('dateFormatter');?>
<div id="$ROOT">
  ...
  <p>Now time:<?=dateFormatter.parse(new Date(), 'yyyy-MM-dd HH:mm:ss') ?></p>
  ...
</div>
<script>
var $ = require('jquery');
var vDialog = require('vDialog');
$ROOT = $(ROOT);
$ROOT.find(...
vDialog.alert(...
</script>

Diversification Support

nodetpl can support a variety of conventional development and modular development, according to their project requirements you can choose any one development model.

Develop common pattern is relatively simple, let's look at the modular development.

AMD(requireJs)

Not precompiled (not recommended):

By require the nodetpl module introduced:

define(function(require, exports, module) {
  var nodetpl = require('nodetpl');
  var data = {
    "title": "Favor",
    "favor": [
      "Football",
      "Basketball",
      "Table tennis",
      "Glass ball"
    ]
  };
  nodetpl.get('/demo/tpls/1.tpl', data, function(d) {
    // d
  });
});

After precompiled, nodetpl don't need to be required:

define(function(require, exports, module) {
  //var nodetpl = require('nodetpl');
  var data = {
    "title": "Favor",
    "favor": [
      "Football",
      "Basketball",
      "Table tennis",
      "Glass ball"
    ]
  };
  var tpl = require('./demo/tpls/1');
  var result = tpl.render(data);
  console.log(result);
});

Have a tryView demo

Through the require for synchronous requirement, this is a way of execution efficiency is highest. If you want to change to asynchronous requirement, do you still need to require nodetpl lib file, and then use nodetpl.get:

define(function(require, exports, module) {
  var nodetpl = require('nodetpl');
  var data = {
    "title": "Favor",
    "favor": [
      "Football",
      "Basketball",
      "Table tennis",
      "Glass ball"
    ]
  };
  var tpl = nodetpl.get('./demo/tpls/1', data, function(d) {
    console.log(d);
  });
});

CommonJs(node.js)

node.js is almost the same with AMD/CMD above:

var tpl = require('./demo/tpls/1');
var data = {
  "title": "Favor",
  "favor": [
    "Football",
    "Basketball",
    "Table tennis",
    "Glass ball"
  ]
};
var result = tpl.render(data);
console.log(result);

Communication