Skip to content

Commit

Permalink
doc: update readme exampels
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Nov 15, 2021
1 parent 3aac8e1 commit a80b408
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,14 @@ My develop tags:
- java
```

### More usage
## More usage

**config template**
The syntax is the same as that of the PHP native template, and the special syntax is added just to make it easier to use.

-`EasyTemplate` enables output filtering by default, which can be used to render view templates
-`TextTemplate` turns off output filtering and is mainly used for text processing, code generation, etc.

### Config template

```php
use PhpPkg\EasyTpl\EasyTemplate;
Expand All @@ -96,7 +101,7 @@ $t->addFilters([]);
$t->addDirective($name, $handler);
```

**echo variable**
### Echo variable

The following statements are the same, can be used to print out variable values

Expand All @@ -119,7 +124,7 @@ More:
- Set to disable output filtering `$t->disableEchoFilter()`
- Disable output filtering in the template `{{ $name | raw }}`

**chained access array**
### Chained access array

Can use `.` to quick access array value.

Expand All @@ -137,7 +142,7 @@ First value is: {{ $arr.0 }} // val0
'subKey' value is: {{ $arr.subKey }} // val1
```

**if blocks**
### If blocks

only `if`:

Expand Down Expand Up @@ -173,7 +178,7 @@ age is {{ $age }}, and
{{ endif }}
```

**for/foreach blocks**
### For/Foreach blocks

`foreach`:

Expand All @@ -197,7 +202,7 @@ tags:
{{ endforeach }}
```

**add comments**
### Add comments

```php
{{# comments ... #}}{{ $name }} // inhere
Expand Down
16 changes: 9 additions & 7 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,14 @@ My develop tags:
- java
```

### 更多使用
## 更多使用说明

语法跟PHP原生模板一样的,加入的特殊语法使用只是为了使用更加方便。

- `EasyTemplate` 默认开启输出过滤,可用于渲染视图模板
- `TextTemplate` 则是关闭了输出过滤,主要用于文本处理,代码生成等

**配置设置**
### 配置设置

```php
use PhpPkg\EasyTpl\EasyTemplate;
Expand All @@ -99,7 +101,7 @@ $t->addFilters([]);
$t->addDirective($name, $handler);
```

**输出变量值**
### 输出变量值

下面的语句一样,都可以用于打印输出变量值

Expand All @@ -121,7 +123,7 @@ $t->addDirective($name, $handler);
- 设置禁用输出过滤 `$t->disableEchoFilter()`
- 模板中禁用输出过滤 `{{ $name | raw }}`

**快速访问数组值**
### 快速访问数组值

可以使用`.` 来快速访问数组值。

Expand All @@ -139,7 +141,7 @@ first value is: {{ $arr.0 }} // val0
'subKey' value is: {{ $arr.subKey }} // val1
```

**if 语句块**
### If 语句块

`if` 语句:

Expand Down Expand Up @@ -175,7 +177,7 @@ age is {{ $age }}, and
{{ endif }}
```

**for/foreach 语句块**
### For/Foreach 语句块

`foreach`:

Expand All @@ -199,7 +201,7 @@ tags:
{{ endforeach }}
```

**模板中添加注释**
### 模板中添加注释

`{{#``#}}` 包裹的内容将会当做注释忽略

Expand Down

0 comments on commit a80b408

Please sign in to comment.