npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

thinkjs-behavior-ejs

v0.0.4

Published

这是一个ThinkJS的插件,实现EJS模版的前后台共享。

Readme

thinkjs-behavior-ejs

这是一个ThinkJS的插件,实现EJS模版的前后台共享。在ThinkJS项目中引入此插件,只需在后台声明一次EJS模版,前台就能复用模版,无需再到前台重新声明。

使用方法

1、引入Behavior

注意! thinkjs v1.1.x 及以上版本需要在App/Conf/common.js中前置引入thinkjs-behavior-ejs,如下:

// 这个引入必须前置在定义 ejs filter 之前声明
thinkRequire('thinkjs-behavior-ejs');

App/Conf/tag.js中写入代码:

var ejsBehavior = thinkRequire('thinkjs-behavior-ejs');
module.exports = {
    view_parse: [false, function(http, data) { return ejsBehavior(http).run(data); }]
};

参考:ThinkJS Behavior

2、声明需要共享模版的action

App/Conf/config.js写入配置:

ejs_behavior_actions: ['home/index/list']

提示:action需要写完整路径,不能写缩写,比如配置了route的缩写。

3、创建模版目录

在对应的App/View/[Group目录]下创建文件夹tpl。比如上面写的home/index/list,就是在App/View/Home目录下创建tpl文件夹。

4、创建共享模版

tpl文件夹下创建模版,命名格式:[controller]_[action]_[自定义名称].html

例如:index_list_paging.html,前面index_list与View的模版命名相同,后缀不一定是.html,而是config.js中定义的tpl_file_suffix。参考:ThinkJS 默认配置

5、后台View引用共享模版

在View中,直接使用include引入共享模版。

<% include tpl/index_list_paging.html %>

6、将共享模版输出给前台

在View的页面底部,找一个合适的位置,写入代码:

<script src="/resource/lib/ejs-0.8.6/ejs.min.js"></script>
<%- _ejs_templates %>

提示_ejs_templates不能使用=输出,使用=会被转义。

7、在前台使用模版

在第6步中,_ejs_templates会向页面输出模版代码,并为每个模版重新分配一个id,id格式为:_ejs_tpl_[controller]_[action]_[自定义名称],这个自定义名称就是第4步中提到的模版自定义名称。

那么,前台就能直接使用ejs接口调用模版,如下:

ejs.compile($('#_ejs_tpl_index_list_paging').html());

复杂应用

共享filter

如果你在ThinkJS中需要使用EJS的filter特性,那么,你可以在App/Common/common.js中定义filter,比如:

// ejs 一定要通过 thinkRequire 引入,不要使用 require()
// 如果使用 require() 会导致 View 模版无法找到filter
var ejs = thinkRequire('ejs');

ejs.filters.getVersion = function(o) {
    return 'v' + o.version + '-' + moment(o.create_time).format('YYYYMMDD');
};

当这么定义ejs.filters之后,thinkjs-behavior-ejs会将你声明的filter一并输出到前台,提供给前台使用。

例子

参考:https://github.com/maxzhang/lavaflow