Skip to content

Commit

Permalink
up: update readme add docsfiy config
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Nov 12, 2021
1 parent 1718227 commit 67c3eb7
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 7 deletions.
Empty file added .nojekyll
Empty file.
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,16 @@
## Features

- It's simple, lightweight and fastly.
- It's simple, lightweight and fastly.
- No learning costs, syntax like PHP template
- It is simply processed and converted into native PHP syntax
- Compatible with PHP native syntax
- support simple echo print syntax. eg: `{{= $var }}` `{{ $var }}` `{{ echo $var }}`
- support all control syntax. such as `if,elseif,else;foreach;for;switch`
- support chained access array value. eg: `{{ $arr.0 }}` `{{ $map.name }}` `{{ $map.user.name }}`
- More secure, the output will be processed automatically through `htmlspecialchars` by default
- You can set to disable output filtering or manually use the `raw` filter
- support php builtin function as filters. eg: `{{ $var | ucfirst }}`
- support all control syntax. such as `if,elseif,else;foreach;for;switch`
- support add custom filters.
- default builtin filters: `upper` `lower` `nl`
- support add custom directive.
Expand Down Expand Up @@ -84,6 +87,32 @@ $t = EasyTemplate::new([
// do something ...
```

更多设置:

```php
/** @var PhpPkg\EasyTpl\EasyTemplate $t */
$t->disableEchoFilter();
$t->addFilter($name, $filterFn);
$t->addFilters([]);
$t->addDirective($name, $handler);
```

**echo variable**

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

```php
{{ $name }}
{{= $name }}
{{ echo $name }}
```

> By default, the output result will be automatically processed through `htmlspecialchars`,
> unless disabled or manually used `raw` filter
- Set to disable output filtering `$t->disableEchoFilter()`
- Disable output filtering in the template `{{ $name | raw }}`

**chained access array**

Can use `.` to quick access array value.
Expand Down
41 changes: 36 additions & 5 deletions README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
[![GitHub tag (latest SemVer)](https://img.shields.io/github/tag/phppkg/easytpl)](https://github.com/phppkg/easytpl)
[![Actions Status](https://github.com/phppkg/easytpl/workflows/Unit-Tests/badge.svg)](https://github.com/phppkg/easytpl/actions)

⚡️ 简单快速的 PHP 模板引擎
⚡️ 简单快速的 PHP 模板引擎

> **[EN-README](README.md)**
## 功能特性

- 简单、轻量且快速。
- 无学习成本
- 仅仅简单处理并转换为原生PHP语法
- 兼容PHP原生语法使用
- 支持简单的输出语法。 例如:`{{= $var }}` `{{ $var }}` `{{ echo $var }}`
- 支持所有控制语法。 `if,elseif,else;foreach;for;switch`
- 更加简单的输出语法。 例如:`{{= $var }}` `{{ $var }}` `{{ echo $var }}`
- 支持所有控制语法。 例如 `if,elseif,else;foreach;for;switch`
- 支持链式访问数组值。 例如:`{{ $arr.0 }}` `{{ $map.name }}` `{{ $map.user.name }}`
- 支持使用 PHP 内置函数作为过滤器。 例如:`{{ $var | ucfirst }}`
- 更加安全,默认会自动通过 `htmlspecialchars` 将输出结果进行处理
- 除非设置了禁用或者手动使用 `raw` 过滤器
- 支持使用PHP内置函数作为过滤器。 例如:`{{ $var | ucfirst }}`
- 支持添加自定义过滤器
- 默认内置过滤器:`upper` `lower` `nl`
- 支持添加自定义指令,提供自定义功能
Expand Down Expand Up @@ -71,6 +74,9 @@ My develop tags:

### 更多使用

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

**配置设置**

```php
Expand All @@ -84,6 +90,31 @@ $t = EasyTemplate::new([
// do something ...
```

更多设置:

```php
/** @var PhpPkg\EasyTpl\EasyTemplate $t */
$t->disableEchoFilter();
$t->addFilter($name, $filterFn);
$t->addFilters([]);
$t->addDirective($name, $handler);
```

**输出变量值**

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

```php
{{ $name }}
{{= $name }}
{{ echo $name }}
```

> 默认会自动通过 `htmlspecialchars` 将输出结果进行处理,除非设置了禁用或者手动使用 `raw` 过滤器
- 设置禁用输出过滤 `$t->disableEchoFilter()`
- 模板中禁用输出过滤 `{{ $name | raw }}`

**快速访问数组值**

可以使用`.` 来快速访问数组值。
Expand Down Expand Up @@ -174,7 +205,7 @@ $tpl = EasyTemplate::new();
// use php built function
$tpl->addFilter('upper', 'strtoupper');

// add more
// 一次添加多个
$tpl->addFilters([
'last3chars' => function (string $str): string {
return substr($str, -3);
Expand Down
3 changes: 3 additions & 0 deletions _navbar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

* [En](/README.md)
* [中文](/README.zh-CN.md)
24 changes: 24 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta charset="UTF-8">
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsify/themes/vue.css">
<title>Easy Template</title>
</head>
<body>
<div id="app"></div>
<script>
window.$docsify = {
repo: 'phppkg/easytpl',
maxLevel: 3,
// 加载 _navbar.md
loadNavbar: true,
// 加载 _sidebar.md
// loadSidebar: true,
}
</script>
<script src="//cdn.jsdelivr.net/npm/docsify/lib/docsify.min.js"></script>
</body>
</html>
File renamed without changes.

0 comments on commit 67c3eb7

Please sign in to comment.