创建链接以用预填信息启动新主题

:bookmark: 本文档介绍如何创建以在 Discourse 中启动新主题并预先填充信息的链接。

:person_raising_hand: 所需用户级别:所有用户

有时您可能希望向用户提供一个链接,该链接会打开一个新的主题撰写器并预先填充某些信息。这对于各种用例都非常有用,包括错误报告模板、功能请求或标准化帖子。

构造 URL

基础 URL

要创建不带任何额外信息的新预填充主题,请将 /new-topic 附加到您的站点 URL,如下所示:

https://discourse.example.com/new-topic

点击此链接将为任何已登录的用户打开一个空白的新主题撰写器(如果未登录,系统会提示您先登录/注册,然后再打开撰写器)。

附加参数

虽然打开空白撰写器的链接有时很有用,但此功能的主要优势在于能够用额外信息预填充撰写器。

为此,您可以向基础 URL 添加参数:

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

这将打开一个预先填充了主题标题、正文、类别和标签的撰写器窗口。

分解链接/URL 以显示可用选项,我们有:

  • 基础 URL: https://discourse.example.com/new-topic
  • ? URL 运算符,用于添加不同的选项
  • 主题标题: title=topic%20title
  • &,每次包含另一个参数时使用
  • 正文: body=topic%20body
  • 如果要包含类别子类别,则用斜杠 / 分隔:category=category/subcategory
  • 如果要包含多个标签,则用逗号 , 分隔:tags=email,planned

每个参数都是可选的,可以根据您期望的最终结果混合搭配。

作为使用类别/子类别名称的替代方法,您可以用数字 category_id 替换它,例如:

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

示例

您可以在 Meta 上尝试一下:

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

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

:exclamation: 不过请不要真的创建主题 :slight_smile: 要更亲手探索此功能,请使用我们的演示站点 try.discourse.org

使用浏览器开发者工具

打开浏览器控制台 (F12 → Console) 并使用内置的 URLSearchParams 来构建 URL——它会自动处理所有百分比编码:

const base = 'https://discourse.example.com/new-topic';
const url = base + '?' + new URLSearchParams({
  title: 'My topic title',
  body: `Body text here...
supports multi line`,
  category: 'support',
  tags: 'bug,urgent'
});
console.log(url); // 复制此 url

将预填充的 URL 与精选链接一起使用

此功能也支持精选链接,前提是未包含 body 参数。

:information_source: 必须对 URL 进行 URL 编码链接才能工作。

例如,要创建包含以下 URL 的主题 https://www.xkcd.com/556,链接将是:

https://meta.discourse.org/new-topic?title=https%3A%2F%2Fwww.xkcd.com%2F556

最佳实践

  • w3Schools 的HTML URL 编码参考是查找文本字符在 URL 中如何编码的良好资源。如果您需要添加大量文本,‘Try It Yourself’ 部分也提供了文本到 URL 的转换器。
  • 始终对参数进行 URL 编码,以避免特殊字符导致的问题。
  • 如果不确定类别 ID,可以通过查看类别 URL 中的数字来检查它。(例如:https://meta.discourse.org/c/documentation/using-discourse/126
  • 测试预填充的链接以确保它们按预期工作。

:information_source: 目前无法使用预填充的链接来回复特定主题并打开撰写器。

附加资源

89 个赞
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?
Open Composer with Prefilled information
Unlisted categories
URL to set up new topic and category, tags
Problem in sso redirection for compose a new pre-filled topic via URL
Pre-filled topics don't recognize subcategories anymore
Topic-specific reply template
Rename @discobot's start new user command
Bookmarklet or chrome extension for posting links to a Discourse
Add one button for topic create with pre-filled content without composer or API?
How Coinbase Uses Discourse to Educate Customers and Improve SEO
Link to New Topic?
Link to create a new topic with parsed values in GET-method data?
[PAID] extra input fields for new topic
How to "replace" +New Topic with a custom button that brings up the composer
Discourse Templates
Create new topic via URL and set tag or category
Wording for private/secure categories
Topic-specific reply template
Topic-specific reply template
How to add a "button" which composes a pre-filled topic
Start a topic by pasting a link (like Reddit)
Link to start a topic with a pre-filled attachment file
How to create a post clicking a link?
Is there any link to open composer (for hyperlink)?
"push" sso users to discourse?
Post commits via webhook inside a topic as reply
Was this Article helpful? Yes or No
Gitter: Post notifications to chat, post transcripts to forum
How to make all users who sign up or accept in invite go to a specifed category(with post composer open)
Category-specific "new topic" email address/url in notification email?
Open new topic composer in a separate window
Onboarding: Discobot, automated messages, other options?
Deep link to new topic or account creation
Alerts that react to the user
Feedback form / reporting bugs
How to have a reply link with pre-filled information?
How do I create a link which opens Create Topic?
Create a link that will open the editor with a specific category and a specific tag
Any Direct URL To New Topic Page?
Creating pre-filled personal message links
URL for "Sign Up" or "Create Topic"?
Link to "Create new topic" and passing tag and category with query var?
Opening a reply window via URL
How do I create a link which opens Create Topic?
Opening a reply window via URL
Prefilled composer link generator
[Solved] In plugin: opening the composer without changing the route
URL to start new post
New Topic Create URL is not working for Subcategory
Create new topic in category with specific tag via URL
Is there a way to make an input form for structured data?
Placeholder Forms
Direct link to composing a comment?
Topic-specific reply template
Creating pre-filled personal message links
Oneboxing not working when starting a topic with pre-filled information
Using topic templates for categories
Impossible to copy heading links
Topic Templates
Have url for creating topic with specific title
Oneboxing not working when starting a topic with pre-filled information
Is there a way to link directly to the editing screen?
Directly linking to new-topic not working when default list filter = no sub categories
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