Template Adapter used to support a variety of types of template engines, such as ejs
, swig
, etc.
base
ejs
ejs template enginejade
jade template engine swig
a template engine suports template inheritancenunjucks
a powerful template engine like jinja2 To configuate template engine, edit src/common/config/view.js
:
export default {
type: 'ejs',
options: { // Additional configuration of the specific template engine
}
};
The template engine can be loaded automatically in the View. If you want to specify a template engine, then do it this way:
let EjsTemplate = think.adapter('template', 'ejs');
let instance = new EjsTemplate(...args);
You can create an Template class named foo
using the following command:
thinkjs adapter template/foo
The command creates file src/common/adapter/template/foo.js
.Then, you should implement the following methods:
export default class extends think.adapter.base {
/**
* get compiled content
* @params {String} templateFile the template files directory
* @params {Object} tVar variables in template
* @params {Object} config the configuration of template engine
* @return {Promise} []
*/
run(templateFile, tVar, config){
}
}
To know the implement of Template in ThinkJS, please see also https://github.com/75team/thinkjs/tree/master/src/adapter/template。
To know how to use third part template adaptor, please see alsoAdapter -> intro.