天天看点

Koa(七):art-template 模板引擎

安装

https://aui.github.io/art-template/zh-cn/index.html

npm install --save art-template

npm install --save koa-art-template

示例

Koa(七):art-template 模板引擎
const Koa = require('koa'),
    render = require('koa-art-template'),
    path = require('path'),
    router = require('koa-router')();

const app = new Koa();

render(app, {
    root: path.join(__dirname, 'views'),                // web文件夹
    extname: '.art',                                    // 扩展名 可自定义
    debug: process.env.NODE_ENV !== 'production'        // debug
});

router
    .get('/', async ctx => {

        await ctx.render('index', { name: 'Lee'});

    })

app
    .use(router.routes())
    .use(router.allowedMethods())
    .listen(3000);

console.log('Server run in http://localhost:3000/');
           
<!-- index.art -->
<%= name %>

{{if name}}
<h2>{{ name }}</h2>
{{/if}}
           
Koa(七):art-template 模板引擎