# 动态渲染插件任意帖子的最佳方法

**URL:** https://meta.discourse.org/t/best-way-to-dynamically-render-an-arbitrary-post-from-a-plugin/167678
**Category:** Development
**Created:** [2020年十月19日 20:49 UTC](https://meta.discourse.org/t/best-way-to-dynamically-render-an-arbitrary-post-from-a-plugin/167678 "2020-10-19T20:49:01Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![syl](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/syl/32/98883_2.png) [@syl](https://meta.discourse.org/u/syl)
#### Post date: [2020年十月19日 20:49 UTC](https://meta.discourse.org/t/best-way-to-dynamically-render-an-arbitrary-post-from-a-plugin/167678/1 "2020-10-19T20:49:01Z")

</div>

在我的 DiscPage 插件中，当用户在 `tag` 路由时，我需要在客户端动态创建的 div 中渲染特定的 **post** 。我通过 API 加载了该 post，但在正确渲染（完全处理并装饰）时遇到了问题。

我当前的实现是从头创建了一个 `decoratorHelper`，但缺少一些部分（例如 post 模型），导致与其他插件不兼容。

有什么建议可以继续推进吗？如何在不依赖当前路由的情况下，获取一个干净的 post 相关的 widget/helper？

---

<div class="post-metadata">

### Author: ![fzngagan](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/fzngagan/32/259349_2.png) [@fzngagan](https://meta.discourse.org/u/fzngagan)
#### Post date: [2020年十月19日 21:16 UTC](https://meta.discourse.org/t/best-way-to-dynamically-render-an-arbitrary-post-from-a-plugin/167678/2 "2020-10-19T21:16:29Z")

</div>

你可以尝试使用 `PrettyText.cook`。在代码库中查找客户端和服务端的示例。
