Skip to content

Commit

Permalink
Merge pull request #75 from yibuyisheng/master
Browse files Browse the repository at this point in the history
etpl的expression语法 文档补全
  • Loading branch information
errorrik committed Aug 13, 2017
2 parents b00f1f4 + cfddd45 commit ac305f9
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions doc/syntax.md
Expand Up @@ -465,3 +465,51 @@ filter指令不支持自动结束,必须手工编写`指令结束`。
```html
<!-- /filter -->
```

##### 表达式的特殊语法( expression 和 condition-expression )

`if`指令、`use`指令和`var`指令中的表达式( expression 或者 condition-expression )部分,可以使用动态的数据:

```html
<!-- if: ${arr}[${index}] === 'zhangsan' -->He's name is zhangsan.<!-- /if -->

<!-- var: personName = ${arr}[${index}] -->${personName}

<!-- use: item(name = ${arr}[${index}]) -->
<!-- target: item -->${name}
```

如果传入的数据是:

```json
{
"arr": ["zhangsan"],
"index": 0
}
```

输出的结果为:

```
He's name is zhangsan.
zhangsan
zhangsan
```

其它语法示例:

```html
<!-- 动态对象属性 -->
<!-- var: value = ${object}[${key1}][${key2}] -->

<!-- 三目运算符 -->
<!-- var: nameToShow = ${arr}[${index}] === 'zhangsan' ? 18 : 60 -->

<!-- 数学运算 -->
<!-- var: result = ${num1} + ${num2} + 3 -->

<!-- 字符串运算 -->
<!-- var: result = ${str1} + ${num1} + 'string' -->
```

0 comments on commit ac305f9

Please sign in to comment.