-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #330 from Peefy/builtin-template-function
docs: add builtin template function
- Loading branch information
Showing
5 changed files
with
104 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
title: "template" | ||
linkTitle: "template" | ||
type: "docs" | ||
description: template functions | ||
weight: 100 | ||
--- | ||
|
||
## execute | ||
|
||
`execute(template: str, data: {str:any} = {}) -> str` | ||
|
||
Applies a parsed template to the specified data object and returns the string output. See https://handlebarsjs.com/ for more documents and examples. | ||
|
||
```python3 | ||
import template | ||
|
||
content = template.execute("""\ | ||
<div class="entry"> | ||
{{#if author}} | ||
<h1>{{firstName}} {{lastName}}</h1> | ||
{{/if}} | ||
</div> | ||
""", { | ||
author: True, | ||
firstName: "Yehuda", | ||
lastName: "Katz", | ||
}) | ||
``` | ||
|
||
## html_escape | ||
|
||
`html_escape(data: str) -> str` | ||
|
||
Replaces the characters `&"<>` with the equivalent html / xml entities. | ||
|
||
```python3 | ||
|
||
import template | ||
|
||
content = template.html_escape("""\ | ||
<div class="entry"> | ||
{{#if author}} | ||
<h1>{{firstName}} {{lastName}}</h1> | ||
{{/if}} | ||
</div> | ||
""") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
i18n/zh-CN/docusaurus-plugin-content-docs/current/reference/model/template.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
--- | ||
title: "template" | ||
linkTitle: "template" | ||
type: "docs" | ||
description: 模版操作 | ||
weight: 100 | ||
--- | ||
|
||
## execute | ||
|
||
`execute(template: str, data: {str:any} = {}) -> str` | ||
|
||
将解析过的模板应用于指定的数据对象,并返回字符串输出。查看 https://handlebarsjs.com/ 获取更多文档和示例。 | ||
|
||
```python3 | ||
import template | ||
|
||
content = template.execute("""\ | ||
<div class="entry"> | ||
{{#if author}} | ||
<h1>{{firstName}} {{lastName}}</h1> | ||
{{/if}} | ||
</div> | ||
""", { | ||
author: True, | ||
firstName: "Yehuda", | ||
lastName: "Katz", | ||
}) | ||
``` | ||
|
||
## html_escape | ||
|
||
`html_escape(data: str) -> str` | ||
|
||
将字符 `&"<>` 替换为等效的 html / xml实体。 | ||
|
||
```python3 | ||
|
||
import template | ||
|
||
content = template.html_escape("""\ | ||
<div class="entry"> | ||
{{#if author}} | ||
<h1>{{firstName}} {{lastName}}</h1> | ||
{{/if}} | ||
</div> | ||
""") | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters