# [art-template文档](https://aui.github.io/art-template/zh-cn/docs/index.html)
## 1.安装配置
~~~
npm install --save art-template
npm install --save koa-art-template
~~~
## 2.Example
~~~
const Koa = require('koa');
const render = require('koa-art-template');
const {resolve} = require('path');
const app = new Koa();
render(app, {
root:resolve(__dirname, 'views'),
extname: '.html', //后缀也可以写成.art
debug: process.env.NODE_ENV !== 'production'
});
app.use(async function (ctx) {
await ctx.render('user');
});
app.listen(8080);
~~~
## 3.实例
~~~
const Koa = require('koa');
const router = require('koa-router')();
const render = require('koa-art-template');
const {resolve} = require('path');
const app = new Koa();
/* 配置模板引擎 */
render(app, {
root: resolve(__dirname, 'views'),
extname: '.html',
debug: process.env.NODE_ENV !== 'production'
});
router.get('/', async ctx => {
await ctx.render('index',{name:"chengchao"})
})
app.use(router.routes()).use(router.allowedMethods())
app.listen(8080)
~~~
## 4.基本语法
### 4.1 if
~~~
{{if isShow}}
<p>加载更多</p>
{{/if}
~~~
- if-else
~~~
{{if isShow}}
<p>加载更多</p>
{{else}}
<p>不要加载</p>
{{/if}}
~~~
### 4.2 遍历 each
~~~
{{each arr}}
<p>{{$index}}-{{$value}}</p>
{{/each}}
~~~
### 4.3 模板继承
#### 标准语法
~~~
{{extend './layout.art'}}
{{block 'head'}} ... {{/block}}
~~~
模板继承允许你构建一个包含共同元素的模板“骨架”。范例
~~~
//骨架模板
<!--layout.html-->
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>{{block 'title'}}My Site{{/block}}</title>
{{block 'head'}}
{{/block}}
</head>
<body>
{{block 'content'}}{{/block}}
</body>
</html>
~~~
~~~
//index.js
<!--index.art-->
{{extend './layout.html'}}
{{block 'title'}}{{title}}{{/block}}
{{block 'head'}}
<link rel="stylesheet" href="custom.css">
{{/block}}
{{block 'content'}}
<p>This is just an awesome page.</p>
{{/block}}
~~~
### 4.4 子模板
~~~
{{include './header.html'}}
~~~
### 4.5原文输出
~~~
{{@value}}
~~~
- 第一章 入门
- 1-1 项目技术栈
- 1-1 promise
- 1-1-1 promise-ajax
- 1-1-1 util.promisify
- 1-2 async
- 1-2-1 async-await
- 1-2-2 async-util.promisify
- 1-3 async-map
- 1-3 iterator
- 1-4 generator
- 1-4-1 generator基础
- 1-4-2 generator-ajax
- 1-5 process
- 1-0 参考教程
- 1-6 静态方法
- 1-7 单例
- 第二章 ES-7
- 2-1 co
- 2-2 异步读取文件
- 2-3 co-ajax
- 第三章 koa核心
- 3-1 server
- 3-2 koa的中间件
- 3-3 koa-session
- 3-3 koa-router
- 3-3-1 ctx.params动态路由
- 3-4 koa路由get传值
- 3-5 中间件
- 3-5-1匹配路由之前设置一个中间件
- 3-5-2 中间件执行顺序
- 3-5-3 错误处理中间件
- 3-6 ejs
- 3-6-1 ejs基本语法
- 3-7 koa-post
- 3-8 koa-static静态资源中间件
- 3-9 art-template
- 3-10 koa-cookie的使用
- 3-11 koa-session
- 3-12 koa应用生产器
- 第四章
- 第一节 pug模板
- 第二节 puppeteer爬虫
- 2-1 爬取豆瓣top250数据
- 2-2 爬取豆瓣剧情页数据
- 第三节 将数据上传到七牛
- 第五章 mongoBD
- 5-1 安装
- 5-2 基本命令
- 5-3 mongoose连接数据库
- 5-3-1 简单连接数据库
- 5-3-2 schema,model,entity
- 5-3-3 schema向数据库中添加数据
- 5-3-4 豆瓣数据添加到数据库
- 5-3-5 glob引入schema
- 5-3-6 schema的数据类型
- 5-4 从数据库取得数据返回给前台
- 5-5 mongo数据库取数据生成接口