开发 Discourse 插件 - 第 2 部分 - 连接到插件出口

Yes, and presumably you can apply to every available Theme so this can’t be switched off? (to address @sarahann concern about this approach).

I could use display: none but it might now be as secure as we need it to be. And I figured it would be helpful to have a discussion on how to remove / change Discourse UI templates.

2 个赞

It’s tricky to do properly, unfortunately. For a big customer of ours who needs functionality removed, my approach has been to hide the elements with CSS and remove the controller side actions by using add_to_class to overwrite the methods with an error in plugin.rb.

9 个赞

I have a same problem. I’m working on plugin with topic, and I have to change the html structures but it’s impossible with only CSS. So I was tried to overwrite template but changes never applied.
So do you have find any solution for that?

You can override any template in the application if you like (although outlets are always preferred!). How were you doing it? did you confirm the name is exactly the same as the template you are replacing?

3 个赞


I tried to override the “list/topic-list-item.raw.hbs” template, but even though I removed all of the content in template, the topic items still appearing as original, any changing in override template never worked.
Please help me what I was wrong.

See: https://github.com/SamSaffron/discourse-simple-theme for an example of how it is done.

4 个赞

Hello,
When I run the command git grep “plugin-outlet” – “*.hbs” in my Linux Terminal, nothing shows up. Any ideas why? Thanks for your help!

Caveat: This is a sysadmin answer, not a plugin developer answer, and I can’t guess what you might have done before you did your git command.

Did you add it to git? What about

 grep -r plugin-outlet .
2 个赞

Building on Jay’s shoulders here, you can of course focus on the specific file type:

grep -r "plugin-outlet" --include \*.hbs

3 个赞

Is there anything you need to consider differently if the plugin outlet looks like this?

{{plugin-outlet name="users-top" connectorTagName="div" args=(hash model=model)}}

do the connectorTagName and args attributes mean that plugin developers have particular constraints or extra accesses when using these outlets?

Yes you are meant to work with the API that the outlets establish.

In the users-top you are passed a model which you can use, and the connector will be rendered with a div in this case.

2 个赞

我找不到 {{plugin-outlet}}。我找到了一些同名组件。它们是相同的吗?

grafik

1 个赞

我认为 Discourse 的代码已更改,指南可能已过时。

正在查找此示例:

我找到了这个:

https://github.com/discourse/discourse/blob/main/app/assets/javascripts/discourse/app/templates/topic.hbs#L80

并使用这个很棒的主题组件 https://meta.discourse.org/t/plugin-outlet-locations-theme-component/100673,我可以看到这个 outlet 在它应该在的地方:

回答你的问题,我猜它是一样的,但使用了新的语法。

3 个赞

我也找到了这个标签。有人能确认它们都一样吗?

{{~raw-plugin-outlet name="topic-list-after-title"}}

关于插件插槽的最新参考资料在此处:

我将在未来几天内尝试更新 OP。

5 个赞

OP 已更新为新语法,并附有指向完整文档的链接

6 个赞

我认为该命令应更新为:

git grep "<PluginOutlet" -- "*.gjs"

该链接显示“已弃用”。

编辑: 我在顶部帖子下方找到了提交 PR 的链接,所以我提交了一个 PR。

1 个赞

已替换为:

https://meta.discourse.org/t/introducing-discourse-developer-toolbar/346215?u=merefield

2 个赞