-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
feat: add supports for provide theme templates in plugin class path #4862
Conversation
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #4862 +/- ##
============================================
- Coverage 56.88% 56.85% -0.03%
- Complexity 2975 2984 +9
============================================
Files 514 516 +2
Lines 16912 16984 +72
Branches 1273 1280 +7
============================================
+ Hits 9621 9657 +36
- Misses 6750 6784 +34
- Partials 541 543 +2 ☔ View full report in Codecov by Sentry. |
/ping @halo-dev/sig-halo |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
Hi @guqing ,如果多个插件中都提供了模板 |
插件只会访问到插件自己的模板,因为使用的时候要求加上自己插件名如 ServerResponse.ok().render('plugin:fake-plugin:halo.html', Map.of()); 如果不加前缀访问的会是主题的模板,以下是一个可能的使用示例: 它表示优先使用主题的 doc.html 模板,如果模板不存在就会返回 plugin:docsme:doc 作为模板名然后会使用到插件的 classpath:/templates/doc.html 如果说多个插件都定义了路由 /halo 那么路由就冲突了要看路由会访问到哪个插件,而如果路由没有冲突的情况下使用哪个插件的路由就是用哪个插件的模板 |
模板是插件只能访问自己的模板,但如果多个插件定义了相同的路由那就是路由冲突的问题了。 |
明白了。PR 描述中确实没有看出来具体该怎么用。后续可能也需要完善一下插件开发文档。 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JohnNiang The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind feature
/milestone 2.11.x
/area core
What this PR does / why we need it:
插件支持在 templates 目录提供默认模板
由于模板解释时只有模板名称无法区分该从哪里解析模板,默认是从主题,但插件提供的模板需要从插件的 classpath 下使用插件的 classloader 加载,所以需要特殊标记模板来让模板解析知道从哪个插件加载,规则为
plugin:{pluginName}:{templateName}
如在 fake-plugin 插件下的模板 layout.html 中定义一个 fragment 片段
那么在其他模板使用 fragment 时需要在 th:replace 的模板名称前加上前缀
Which issue(s) this PR fixes:
Fixes #4858
Does this PR introduce a user-facing change?