How to create a new topic link with pre-filled information

Discourse now supports composing a new (pre-filled) topic via URL! To compose a new pre-filled topic, modify URL params like this:

https://discourse.example.com/new-topic?title=topic%20title&body=topic%20body&category=category/subcategory&tags=email,planned

This will open composer window pre filled with topic title, body, category and tags.

Breaking down the link / URL to show the available options, we have:

  • the base URL / link: https://discourse.example.com/new-topic
  • the ? URL operator to add the different options
  • the topic title: title=topic%20title
  • the & URL operator to include multiple options
  • the body of the topic: body=topic%20body
  • the & URL operator again to include multiple options
  • the category and subcategory separated by a backslash / if you want to include them: category=category/subcategory
  • the & URL operator again to include multiple options
  • and the tags separated by comma(s) , if you want to include multiple tags: tags=email,planned

Try it out live, here on meta! :smile:

https://meta.discourse.org/new-topic?title=topic%20title&body=topic%20body&category=support/wordpress&tags=wordpress

Also, instead of providing category/subcategory name, you can also specify a numeric category_id, like:

https://meta.discourse.org/new-topic?title=topic%20title&body=topic%20body&category_id=3&tags=wordpress

This feature also supports “Start a topic by pasting a link (like Reddit)”, provided that the body is not present, for example:

https://meta.discourse.org/new-topic?title=https://www.xkcd.com/556

If you have a lot of text to add, you can use w3Schools’s HTML URL Encoding Reference to find what text characters are encoded as in the URL, there is even a text to URL converter in the Try It Yourself section in the page linked above in this paragraph.


Want to create / compose a new pre-filled personal message instead? See: How to create a new personal message via a link with pre-filled information

65 Likes
Start creating a new topic via link?
Link that pre-populates the composer?
Fill in post for user?
What is the best way to integrate member applications?
How to open reply window via URL
Unlisted categories
Add one button for topic create with pre-filled content without composer or API?
Link to create a new topic with parsed values in GET-method data?
Bookmarklet or chrome extension for posting links to a Discourse
Rename @discobot's start new user command
How Coinbase Uses Discourse to Educate Customers and Improve SEO
Open Composer with Prefilled information
Feature request: Topic-specific reply template
How to open reply window via URL
Wording for private/secure categories
Feature request: Topic-specific reply template
Feature request: Topic-specific reply template
Feature request: Topic-specific reply template
How to add a "button" which composes a pre-filled topic
Versatile Banner
Start a topic by pasting a link (like Reddit)
Discourse Tab Bar for Mobile
Pre-filled topics don't recognize subcategories anymore
Is there any link to open composer (for hyperlink)?
Problem in sso redirection for compose a new pre-filled topic via URL
"push" sso users to discourse?
[PAID] extra input fields for new topic
How to "replace" +New Topic with a custom button that brings up the composer
Post commits via webhook inside a topic as reply
Was this Article helpful? Yes or No
Category-specific "new topic" email address/url in notification email?
How to create a new personal message via a link with pre-filled information
Deep link to new topic or account creation
How to create a post clicking a link?
[Solved] In plugin: opening the composer without changing the route
Any Direct URL To New Topic Page?
Have url for creating topic with specific title
Topic Templates
DiscourseConnect - Official Single-Sign-On for Discourse (sso)
Is there a way to make an input form for structured data?
Create new topic in category with specific tag via URL
New Topic Create URL is not working for Subcategory
URL to start new post
How do I create a link which opens Create Topic?
How do I create a link which opens Create Topic?
Open new topic composer in a separate window
Gitter: Post notifications to chat, post transcripts to forum
Chrome/Firefox extension "Share to discourse"
How to add%{post_url} in customize URL
How to auto set topic title?
How can I create a new topic in Discourse via a link or direct the person to the topic if it exists
Link to New Topic?
Create new topic via URL and set tag or category

When you create a /new-topic?category=something the current page is /c/something.

Is there any way to make it render the /tag/something page when creating a /new-topic?tags=something?

Is this something that would get accepted as a PR or is this possible in a custom plugin?

6 Likes

Definitely. PR is 100% welcome!

8 Likes

It seems that the /new-topic?... path only works if you add it to certain pages (like category pages). If you add it to a page that, in some way, is not setup to show the composer, you’ll get an oops error page. For example, if you add that path to this page, it will show an error.

Is there a way to be able to add that /new-topic?... to a new page?

Details

In my plugin, I’m trying to add a create-new topic button to a new page. The trick is to then get the composer to open on that new page when you click the button.

I’ve tried getting into the weeds of how the composer is called (using posts like this as a resource), but it’s a bit slow-going.

It would be cool if I could just add a button to my new page, and on click go the a new topic link.

But, it seems that simply adding /new-topic?title=topic%20title&body=topic%20body to my new page’s url doesn’t work. In some way, right now, the new topic composer can only appear on certain pages (a category home page, for example).

Is there a way to make this work so that I can add the new-topic url info to a new page?

What happens if you create an absolute link by including your forum’s base URL? For example, the way the link is constructed in this topic’s OP:

https://discourse.example.com/new-topic?title=topic%20title&body=topic%20body&category=category/subcategory&tags=email,planned

3 Likes

I don’t think that would enable what I’m trying to do (unless I am missing something–I guess I am not sure what you mean by absolute link).

If I add the /new-topic? to the base url, that does work to bring up the composer. But I am aiming to load the composer on a different page.

In my case, I want to load it on a new page I have created (a new route/path and template). But I think the issue still (probably) applies for other existing pages that don’t normally show the composer.

For example, if I wanted to add a link to this show topic page https://meta.discourse.org/t/how-to-create-a-new-topic-link-with-pre-filled-information/28074/40, so that the composer would appear on a topic show page like that, can I do that?

It works if I use the theme component that loads a new topic button on every page. With that component, I am able to have the composer appear on each page in my live site.

But what about doing it just with the link? like:

https://meta.discourse.org/t/how-to-create-a-new-topic-link-with-pre-filled-information/28074/new-topic?title=topic%20title&body=topic%20body

Doesn’t work for now. And I am wondering how to make that kind of link work.

I’d wonder if you gain that much making it work with that kind of link. If you use the /new-topic url it will always have two disruptive effects:

  • a full page-reload
  • you will be re-directed to the default homepage (as /latest, /categories,…).

If you want the composer to open without a page-reload and stay on the currently visited page, I believe you need to feed your arguments to the composer in a component.

3 Likes