mirror of
https://github.com/halo-dev/docs.git
synced 2025-10-19 08:43:55 +00:00
docs: add documentation for theme error template (#287)
添加主题错误模板的文档。 /kind documentation Fixes https://github.com/halo-dev/docs/issues/144 ```release-note None ```
This commit is contained in:
45
docs/developer-guide/theme/template-variables/error.md
Normal file
45
docs/developer-guide/theme/template-variables/error.md
Normal file
@@ -0,0 +1,45 @@
|
||||
---
|
||||
title: 错误页面
|
||||
description: 关于错误页面的模板变量
|
||||
---
|
||||
|
||||
## 路由信息
|
||||
|
||||
- 模板路径:`/templates/error/{404,4xx,500,5xx,error}.html`
|
||||
- 访问路径:无固定访问路径,由异常决定
|
||||
|
||||
:::info 提示
|
||||
错误页面的可使用模板由状态码决定,例如 404 状态码对应的模板为 `/templates/error/404.html` 或者 `/templates/error/4xx.html`。也可以使用 `/templates/error/error.html` 作为默认模板。
|
||||
|
||||
识别顺序如下:
|
||||
|
||||
1. `/templates/error/404.html`
|
||||
2. `/templates/error/4xx.html`
|
||||
3. `/templates/error/error.html`
|
||||
:::
|
||||
|
||||
## 变量
|
||||
|
||||
### error
|
||||
|
||||
#### 变量类型
|
||||
|
||||
```json
|
||||
{
|
||||
"detail": "string", // 异常详细信息
|
||||
"instance": "string", // 异常实例
|
||||
"status": "number", // 异常状态码
|
||||
"title": "string", // 异常标题
|
||||
"type": "string" // 异常类型
|
||||
}
|
||||
```
|
||||
|
||||
#### 示例
|
||||
|
||||
```html title="/templates/error/error.html"
|
||||
<div>
|
||||
<h2 th:text="${error.status}"></h2>
|
||||
<p th:text="${#strings.defaultString(error.title, 'Internal server error')}"></p>
|
||||
<p th:if="${not #strings.isEmpty(error.detail)}" th:text="${error.detail}"></p>
|
||||
</div>
|
||||
```
|
@@ -179,6 +179,7 @@ module.exports = {
|
||||
"developer-guide/theme/template-variables/categories",
|
||||
"developer-guide/theme/template-variables/category",
|
||||
"developer-guide/theme/template-variables/author",
|
||||
"developer-guide/theme/template-variables/error",
|
||||
],
|
||||
},
|
||||
{
|
||||
|
@@ -0,0 +1,45 @@
|
||||
---
|
||||
title: 错误页面
|
||||
description: 关于错误页面的模板变量
|
||||
---
|
||||
|
||||
## 路由信息
|
||||
|
||||
- 模板路径:`/templates/error/{404,4xx,500,5xx,error}.html`
|
||||
- 访问路径:无固定访问路径,由异常决定
|
||||
|
||||
:::info 提示
|
||||
错误页面的可使用模板由状态码决定,例如 404 状态码对应的模板为 `/templates/error/404.html` 或者 `/templates/error/4xx.html`。也可以使用 `/templates/error/error.html` 作为默认模板。
|
||||
|
||||
识别顺序如下:
|
||||
|
||||
1. `/templates/error/404.html`
|
||||
2. `/templates/error/4xx.html`
|
||||
3. `/templates/error/error.html`
|
||||
:::
|
||||
|
||||
## 变量
|
||||
|
||||
### error
|
||||
|
||||
#### 变量类型
|
||||
|
||||
```json
|
||||
{
|
||||
"detail": "string", // 异常详细信息
|
||||
"instance": "string", // 异常实例
|
||||
"status": "number", // 异常状态码
|
||||
"title": "string", // 异常标题
|
||||
"type": "string" // 异常类型
|
||||
}
|
||||
```
|
||||
|
||||
#### 示例
|
||||
|
||||
```html title="/templates/error/error.html"
|
||||
<div>
|
||||
<h2 th:text="${error.status}"></h2>
|
||||
<p th:text="${#strings.defaultString(error.title, 'Internal server error')}"></p>
|
||||
<p th:if="${not #strings.isEmpty(error.detail)}" th:text="${error.detail}"></p>
|
||||
</div>
|
||||
```
|
@@ -160,7 +160,8 @@
|
||||
"developer-guide/theme/template-variables/tag",
|
||||
"developer-guide/theme/template-variables/categories",
|
||||
"developer-guide/theme/template-variables/category",
|
||||
"developer-guide/theme/template-variables/author"
|
||||
"developer-guide/theme/template-variables/author",
|
||||
"developer-guide/theme/template-variables/error"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
Reference in New Issue
Block a user