# 内置

框架内置的模板渲染引擎为nunjucks (opens new window)

# nunjucks

访问nunjucks (opens new window)查看具体用法

src/welcome.ts

import { Get, Inject, Provide } from '@midwayjs/decorator';
import { Context } from 'egg';
import { CoolController, BaseController } from 'midwayjs-cool-core';

/**
 * 欢迎界面
 */
@Provide()
@CoolController('/')
export class WelcomeController extends BaseController {
  @Inject()
  ctx: Context;

  @Get('/')
  public async welcome() {
    await this.ctx.render('welcome', { text: 'HELLO COOL-ADMIN' });
  }
}

src/app/view

<!DOCTYPE html>
<html lang="en">

<head>
	<meta charset="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<meta http-equiv="X-UA-Compatible" content="ie=edge" />
	<title>COOL-AMIND 一个很酷的后台权限管理系统</title>
	<meta name="keywords" content="cool-admin,后台管理系统,vue,element-ui,nodejs" />
	<meta name="description" content="element-ui、egg.js、midway.js、mysql、redis、node.js、前后端分离、权限管理、快速开发, COOL-AMIND 一个很酷的后台权限管理系统" />
	<link rel="stylesheet" href="css/welcome.css">

<body>
<div class="reveal">{{text}}</div>
<script src="js/welcome.js"></script>
</body>

</html>

# 插件

midway也可以使用egg的插件,直接在src/plugin.ts开启,当然你需要提前安装该依赖包:egg-view-nunjucks

import { EggPlugin } from 'egg';
export default {
  nunjucks: {
    enable: true,
    package: 'egg-view-nunjucks',
  },
} as EggPlugin;

# 路径

// 模板渲染 用法 https://nunjucks.bootcss.com
config.view = {
    root: [path.join(appInfo.baseDir, 'app/view')].join(','),
    defaultViewEngine: 'nunjucks',
    defaultExtension: '.html',
    mapping: {
      '.html': 'nunjucks',
    },
};