2.2.7 • Published 3 years ago

think_view v2.2.7

Weekly downloads
1
License
MIT
Repository
-
Last release
3 years ago

介绍


npm version

View engine Middleware for ThinkKoa.

安装


npm i think_view

使用


Thinkkoa

1、项目中增加中间件

think middleware view

2、修改 middleware/view.js:

module.exports = require('think_view');

3、项目中间件配置 config/middleware.js:

list: [...,'view'], //加载的中间件列表
config: { //中间件配置
    ...,
    view: {
        view_path: process.env.APP_PATH + '/view', //模板目录
        engine_type: 'ejs', //模版引擎名称 ejs, pug
        engine_config: { cache: true }, //模版引擎配置
        content_type: 'text/html', //模版输出类型
        file_suffix: '.html', //模版文件名后缀
        file_depr: '_', //controller和action之间的分隔符
        default_theme: 'default', //默认模板主题
    }
}

Koatty

1、项目中增加中间件

koatty middleware view;

2、修改 middleware/View.ts:

import { Middleware, Helper } from "koatty";
import { App } from '../App';
const jwt = require("think_view");

@Middleware()
export class View {
    run(options: any, app: App) {
        return view(options, app);
    }
}

3、项目中间件配置 config/middleware.ts:

list: [...,'View'], //加载的中间件列表
config: { //中间件配置
    ...,
    View: {
        view_path: process.env.APP_PATH + '/view', //模板目录
        engine_type: 'ejs', //模版引擎名称 ejs, pug
        engine_config: { cache: true }, //模版引擎配置
        content_type: 'text/html', //模版输出类型
        file_suffix: '.html', //模版文件名后缀
        file_depr: '_', //controller和action之间的分隔符
        default_theme: 'default', //默认模板主题
    }
}

渲染模板

// controller
this.assign("test", "aa"); //assign to template
return this.render(process.env.ROOT_PATH + '/static/html/index.html');
....
2.2.7

3 years ago

2.2.5

4 years ago

2.2.6

4 years ago

2.2.4

4 years ago

2.2.3

4 years ago

2.2.2

4 years ago

2.2.1

5 years ago

2.2.0

5 years ago

2.1.0

5 years ago

2.0.2

5 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.6

7 years ago

1.1.5

7 years ago

1.1.4

7 years ago

1.1.3

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago