How can I create a new topic in Discourse via a link or direct the person to the topic if it exists

We have a newsletter made of links to curated external resources. I’d like to add a Discuss link next to each item, which would point to a corresponding topic in our Discourse instance so that the newsletter audience can click to comment and engage others.

I tried using the trick mentioned at Compose a new pre-filled topic via URL, i.e. using a link with /new-topic?title=<url>, but this creates a new topic every time and this is not what I want.

I want the link to show the New Topic controller if the topic doesn’t exist yet, else take the visitor to the existing topic. Is there any way to achieve this with Discourse?

Thank you.

1 Like

Sorry, I updated your topic title to be a bit more descriptive so other users can better find it via search as they look for support.

This will require some logic, and so you will definitely need to build something custom. Not sure if it is a theme component or plugin though, further research will be helpful to see which approach will be better.

5 Likes

I’m not familiar with the Discourse code base yet, but if I were to send a PR, would it be OK to add a new param to the existing /new-topic route, or would you prefer the feature to be isolated in a plugin?

1 Like

Sorry, no.

/new-topic means a new topic.

If the new topic route results in a reply based on params, it would be confusing.

If that doesn’t work for your needs, you can modify the route in a plugin according to your needs.

4 Likes