Skip to content

Latest commit

 

History

History
103 lines (77 loc) · 2.23 KB

README.zh_CN.md

File metadata and controls

103 lines (77 loc) · 2.23 KB

egg-view-xtpl

NPM version build status Test coverage David deps Known Vulnerabilities npm download

egg 的 xtemplate 模板插件

安装

$ npm i egg-view-xtpl --save

用法

配置

// {app_root}/config/plugin.js
exports.xtpl = {
  enable: true,
  package: 'egg-view-xtpl',
};
// {app_root}/config/config.default.js
exports.view = {
  mapping: {
    '.xtpl': 'xtpl',
  },
};

// xtpl config
exports.xtpl = {};

更多参考: config/config.default.js.

示例

Demo

// app/view/hello.xtpl
hello {{ data }}

Render it

// app/controller/render.js
exports.xtpl = function* () {
  yield this.render('hello.xtpl', {
    data: 'world',
  });
};

Include

可以引用相对路径的其他模板:

// app/view/a.xtpl include app/view/b.xtpl
{{ include('./b.xtpl') }}
// app/view/a.xtpl include app/view/c.xtpl
{{ include('c.xtpl') }}
// app/view/banner/item.xtpl include app/view/footer/logo.xtpl
{{ include('../footer/logo.xtpl') }}

问题 & 建议

请在 这里 开 issue.

License

MIT