Skip to content

Commit cbe7794

Browse files
committed
doc: supplement usage doc of etpl.
1 parent ed13a0d commit cbe7794

1 file changed

Lines changed: 55 additions & 7 deletions

File tree

README.md

Lines changed: 55 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ If intending to reference an anchor in different doc, it can be:
7171
[itemStyle](option.html#series.itemStyle)
7272
```
7373

74-
### Notes
74+
75+
### Notice
7576

7677
1. Formatter will treat {{use}} as a block. So don't use it **inline**.
7778

@@ -84,34 +85,81 @@ Some other description
8485
Some description about {{ use: partial-inline-xxx }}
8586
```
8687

87-
2. Don't use to complex **inline** {{if}} {{else}} structure. It will make reading and patching between different languages harder.
88+
2. Don't use complex **inline** {{if}} {{else}} structure. It will make reading and patching between different languages harder.
8889

89-
```js
90-
// Good
90+
```template
91+
Good:
9192
{{ if: ${prefix} !== '#' }}
9293
表示同一层级的节点的颜色饱和度 选取范围。
9394
{{ else }}
9495
本系列默认的节点的颜色饱和度 选取范围。
9596
{{ /if }}
9697
数值范围 0 ~ 1。
9798
98-
// Bad
99+
Bad:
99100
{{ if: ${prefix} !== '#' }}表示同一层级的节点的{{ else }}本系列默认的{{ /if }} 颜色饱和度 选取范围。数值范围 0 ~ 1。
100101
101-
// Good
102+
Good:
102103
{{ if: ${prefix} !== '#' }}
103104
It indicates the range of saturation (color alpha) for nodes in a level.
104105
{{ else }}
105106
It indicates the range of saturation (color alpha) for nodes of the series.
106107
{{ /if }}
107108
The range of values is 0 ~ 1.
108109
109-
// Bad
110+
Bad:
110111
It indicates the range of saturation (color alpha) {{ if: ${prefix} !== '#' }}for nodes in a level {{ else }} of the series{{ /if }}. The range of values is 0 ~ 1.
111112
112113
```
113114

114115

116+
### Template Syntax
117+
118+
The template syntax follows [etpl](https://github.com/ecomfe/etpl/blob/master/doc/syntax.md) (but use `{{ }}` rather than `<!-- -->` as the interpolate tags).
119+
> A syntax highlight tool: [etpl-vscode](https://marketplace.visualstudio.com/items?itemName=yibuyisheng.etpl-vscode)
120+
121+
Summary of the commonly used syntax:
122+
```template
123+
VARIABLE:
124+
some text ${someVariable} some text
125+
126+
127+
IF ELSE:
128+
{{ if: ${number1} > 0 }}
129+
some text xxx
130+
{{ elif: ${string1} === 'abc' }}
131+
some text yyy
132+
{{ else }}
133+
some text zzz
134+
{{ /if }}
135+
136+
137+
FOR LOOP:
138+
{{ for: ${persons} as ${person}, ${index} }}
139+
some text ${index}: ${person.name}
140+
{{ /for }}
141+
142+
143+
TARGET (DEFINE A BLOCK):
144+
{{ target: a_predefined_block_name_1 }}
145+
The input varA is ${varA}
146+
The input varB is ${varB}
147+
The input varC is ${varC}
148+
some other text xxx
149+
(The close target can be omitted, but not recommended.)
150+
{{ /target }}
151+
152+
153+
USE (USE A BLOCK):
154+
{{ use: a_predefined_block_name_1(
155+
varA = ${myVarX},
156+
varB = 123,
157+
varC = 'some string'
158+
)}}
159+
{{ use: a_predefined_block_name_2 }}
160+
```
161+
162+
115163
### Document Embedded Examples
116164

117165
Declare the base echarts options (`ExampleBaseOption`), whose scope is each echarts component or series. A `ExampleBaseOption` can be shared by multiple options. e.g.,

0 commit comments

Comments
 (0)