English | 简体中文

nodetpl methods

NodeTplClass method

Perhaps you have not yet know how to start, so let's look at two common development model:

Conventional model development (not recommended)

Conventional model development, we need to include nodetpl engine, and where it is needed, call the template file directly via get() method:

Browser Direct reference:

<script src="./js/nodetpl.min.js"></script>

AMD/CMD/CommonJs/ES6:

var nodetpl = require('nodetpl');
nodetpl.get('http://www.domain.com/tpls/1.tpl', {
  title: 'Favor'
}, function(d) {
  // console.log(d);
});

However, the actual development process, we generally do not do so, in order to improve execution performance templates, we tend to put precompiled template, then the executable file for reference.

Precompiled high-performance development (recommended)

First use precompile tools precompile the template, then call the compiled executable file directly.

Browser Direct reference:

<script src="./js/nodetpl.min.js"></script>
nodetpl.get('http://www.domain.com/tpls/1', {
  title: 'Favor'
}, function(d) {
  // console.log(d);
});

AMD/CMD/CommonJs/ES6:

// No need to include the nodetpl library, require the compiled js files instead.
var tpl = require('./tpls/1');
var html = tpl.render({
  title: 'Favor'
});
// console.log(html);

The above is called to bring very large performance boost, so the author would recommend the template precompiled.

Communication