开发指南/开发小程序（不推荐）/小程序框架/视图层/TTML
# TTML

TTML 是用来编写页面结构用的标签语言。

要完整了解 TTML的语法，请参考 [TTML语法介绍](https://open.larksuite.com/document/uYjL24iN/uADOuADOuADO)。

主要包括下面一些特性：

## [数据绑定](https://open.larksuite.com/document/uYjL24iN/uADOuADOuADO) 

```html
<view> {{message}} </view>
```

```js
// page.js
Page({
  data: {
    message: 'Hello World!'
  }
})
```

## [列表渲染](https://open.larksuite.com/document/uYjL24iN/uEDOuEDOuEDO) 

```html
<view tt:for="{{array}}"> {{item}} </view>
```

```js
// page.js
Page({
  data: {
    array: [1, 2, 3, 4, 5]
  }
})
```

## [条件渲染](https://open.larksuite.com/document/uYjL24iN/uIDOuIDOuIDO)

```html
<view tt:if="{{view == 'A'}}"> A </view>
<view tt:elif="{{view == 'B'}}"> B </view>
<view tt:else> C </view>
```

```js
// page.js
Page({
  data: {
    view: 'A'
  }
})
```

## [模版](https://open.larksuite.com/document/uYjL24iN/uMDOuMDOuMDO)

```html
<template name="staffName">
  <view>
    FirstName: {{firstName}}, LastName: {{lastName}}
  </view>
</template>

<template is="staffName" data="{{...staffA}}"></template>
<template is="staffName" data="{{...staffB}}"></template>
<template is="staffName" data="{{...staffC}}"></template>
```

```js
// page.js
Page({
  data: {
    staffA: {firstName: '大林', lastName: '斯'},
    staffB: {firstName: '吉尔', lastName: '丘'},
    staffC: {firstName: '福', lastName: '罗思'}
  }
})
```

## [事件](https://open.larksuite.com/document/uYjL24iN/uQDOuQDOuQDO)

```html
<view bindtap="add"> {{count}} </view>
```

```js
// page.js
Page({
  data: {
    count: 1
  },
  add: function(e) {
    this.setData({
      count: this.data.count + 1
    })
  }
})
```
