Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

主题端调用资源的 Annotations 不方便 #3073

Closed
ruibaby opened this issue Dec 29, 2022 · 1 comment · Fixed by #3076
Closed

主题端调用资源的 Annotations 不方便 #3073

ruibaby opened this issue Dec 29, 2022 · 1 comment · Fixed by #3076
Labels
area/core Issues or PRs related to the Halo Core kind/improvement Categorizes issue or PR as related to a improvement.
Milestone

Comments

@ruibaby
Copy link
Member

ruibaby commented Dec 29, 2022

你当前使用的版本

2.1.0-rc.1

描述一下此特性

目前 2.1.0-rc.1 支持了对模型的 Annotations 进行表单定义,目的是为了让插件和主题可以扩展元数据(字段),但目前在主题端调用和判断不是特别方便,请看:

<div
  th:style="|background:${categoryItem.metadata.annotations != null ? (categoryItem.metadata.annotations['bgColor'] ?: '#fff') : ''}|"
></div>
  1. 无法得知 annotations 是否为 null,所以需要判断,防止模板渲染异常。
  2. 调用链过长。

希望针对主题的调用进行优化。

/kind improvement
/area core
/milestone 2.1.x

附加信息

No response

@f2c-ci-robot f2c-ci-robot bot added the kind/improvement Categorizes issue or PR as related to a improvement. label Dec 29, 2022
@f2c-ci-robot f2c-ci-robot bot added this to the 2.1.x milestone Dec 29, 2022
@f2c-ci-robot f2c-ci-robot bot added the area/core Issues or PRs related to the Halo Core label Dec 29, 2022
@guqing
Copy link
Member

guqing commented Dec 29, 2022

提供对象表达式 ${#annotations.get(some-extension, 'halo.run/icon')} 等来获取 annotation
传入的参数为一个包含了 metadata 的 vo

f2c-ci-robot bot pushed a commit that referenced this issue Dec 29, 2022
#### What type of PR is this?
/kind feature
/area core
/milestone 2.1.x
#### What this PR does / why we need it:
新增操作 annotations 的表达式对象
在 thymeleaf 模板中使用示例:
```html
<p th:text="${#annotations.get(user, 'background')}"></p>
<p th:text="${#annotations.getOrDefault(user, 'background', 'default-value')}"></p>
<p th:text="${#annotations.contains(user, 'background')}"></p>
```
#### Which issue(s) this PR fixes:

Fixes #3073

#### Special notes for your reviewer:
/cc @halo-dev/sig-halo 
#### Does this PR introduce a user-facing change?
```release-note
新增 Annotations 表达式对象用于在 thymeleaf 中操作自定义模型的 annotations
```
@JohnNiang JohnNiang modified the milestones: 2.1.x, 2.1.0 Dec 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core Issues or PRs related to the Halo Core kind/improvement Categorizes issue or PR as related to a improvement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants