Hi, I’m working on my first Discourse
plugin.
The idea
We want to alter the tag links behaviour slightly, where, when a tag is clicked anywhere in Discourse, instead of going directly to it, it shows two options; the normal tag url (forum.com/tag/tag-name) or a related (external) page of our choice (something.site.com/some-name). This option would only show for that are in the list.
The list will be in the form of a Ruby array of hashes (or JSON) and this can either be added directly to the plug-in, or be made available at a URL. (The former seems like it will be more resource-friendly - we can just update the list and rebuild the plugin when it updates, as the updates won’t be that often.)
# Ruby array of hashes
array = [
{forum_tag: "discourse", external_slug: "discourse"},
{forum_tag: "dc", external_slug: "discourse"},
{forum_tag: "xenforo", external_slug: "xenforo"},
{forum_tag: "xf", external_slug: "xenforo"}
]
# OR
array.to_json
=> "[{\"forum_tag\":\"discourse\",\"external_slug\":\"discourse\"},{\"forum_tag\":\"dc\",\"external_slug\":\"discourse\"},{\"forum_tag\":\"xenforo\",\"external_slug\":\"xenforo\"},{\"forum_tag\":\"xf\",\"external_slug\":\"xenforo\"}]"
We basically want the option to display like when you click on a replies
number on the main forum page:
My thoughts
I found 2 methods in Discourse
API related to tags:
-
addTagsHtmlCallback
- In this case I would need to settopic.tags
to empty array right after assigning its value to other variable. In that way I would prevent renderingtags
and can write my custom code. -
replaceTagRenderer
- The second one allows me to changetag
render which does not look so hacky as 1st method.
However please look that in both cases I need to return raw
string. From what I found I can’t write and compile Ember
template by hand. Obviously I can just render custom links and write a simple function with jQuery
putting it to root of app/assets/javascripts
, but that’s way different solution comparing to Discourse
code.
Am I on the right track? Any/all help will be very much appreciated.