egg-view-jmteplate

1.0.2 • Public • Published

egg-view-jmtemplate

egg view plugin for jm-template.

Install

$ npm i egg-view-jmtemplate --save

Usage

// {app_root}/config/plugin.js
exports.jmtemplate = {
  enable: true,
  package: 'egg-view-jmtemplate',
  // root: path.join(appInfo.baseDir, 'app/view')
};
 
// {app_root}/config/config.default.js
exports.view = {
  mapping: {
    '.html': 'jmtemplate',
  },
};
 
// htmling config
exports.jmtemplate = {};

Create a jmtemplate file

<!-- banner.html -->
<% for ( var i = 0; i < users.length; i++ ) { %>
    <li><a href="<%=users[i].url%>"><%=users[i].name | add(6) %></a></li>
<% } %>

Render it

// app/controller/render.js
exports.jmtemplate = async ctx => {
  await ctx.render('banner.html', {
    data: {
      users: [
          {url:'http://qqq.com', name: "jiamao"},
          {url:'http://qqq2.com', name: "jiamao2"}
      ]
    },
  }, {
    // 可以传临时filter
    filters: {
      add: (name, len) => return name.substr(0, len || 4)
    }
  });
};

Filters

filter可以写在扩展中, 或者在render时传递。

// {app_root}/app/extend/filter.js
exports.add = (name, len) => return name.substr(0, len || 4);

License

MIT

Package Sidebar

Install

npm i egg-view-jmteplate

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

4.39 kB

Total Files

6

Last publish

Collaborators

  • jiamao