{"meta":{"title":"讨论类别表单的语法","intro":"可以使用 YAML 语法定义讨论类别表单中的字段。","product":"GitHub Discussions","breadcrumbs":[{"href":"/zh/discussions","title":"GitHub Discussions"},{"href":"/zh/discussions/managing-discussions-for-your-community","title":"管理讨论"},{"href":"/zh/discussions/managing-discussions-for-your-community/syntax-for-discussion-category-forms","title":"讨论类别表单的语法"}],"documentType":"article"},"body":"# 讨论类别表单的语法\n\n可以使用 YAML 语法定义讨论类别表单中的字段。\n\n## 关于讨论分类表单的 YAML 语法\n\n可以通过将 YAML 表单定义文件添加到存储库中的 `/.github/DISCUSSION_TEMPLATE/` 文件夹来创建自定义讨论类别表单。 如果你不熟悉 YAML 并且想要了解详细信息，请参阅“[在 Y 分钟内了解 YAML](https://learnxinyminutes.com/docs/yaml/)”。\n\n该名称必须与某个讨论类别的数据域相对应。 例如，“公告”类别的模板应为 `.github/DISCUSSION_TEMPLATE/announcements.yml`。\n\n对于每个字段，可以定义输入类型、验证和默认标签。\n\n当社区成员填写讨论表单时，他们对每个输入的响应都会转换为 Markdown 并添加到讨论正文中。 社区成员可以编辑使用讨论表单创建的讨论，其他人可以像通过其他方法创建的讨论一样与讨论进行交互。\n\n此示例 YAML 配置文件定义一般讨论类别表单。\n\n```yaml copy\ntitle: \"[General] \"\nlabels: [\"General Introduction\"]\nbody:\n  - type: markdown\n    attributes:\n      value: |\n        This is text that will show up in the template!\n  - type: textarea\n    id: improvements\n    attributes:\n      label: Top 3 improvements\n      description: \"What are the top 3 improvements we could make to this project?\"\n      value: |\n        1.\n        2.\n        3.\n        ...\n      render: bash\n    validations:\n      required: true\n  - type: markdown\n    attributes:\n      value: |\n        ## Markdown header\n        And some more markdown\n  - type: input\n    id: has-id\n    attributes:\n      label: Suggestions\n      description: A description about suggestions to help you\n    validations:\n      required: true\n  - type: dropdown\n    id: download\n    attributes:\n      label: Which area of this project could be most improved?\n      options:\n        - Documentation\n        - Pull request review time\n        - Bug fix time\n        - Release cadence\n    validations:\n      required: true\n  - type: checkboxes\n    attributes:\n      label: Check that box!\n      options:\n        - label: This one!\n          required: true\n        - label: I won't stop you if you check this one, too\n  - type: markdown\n    attributes:\n      value: |\n        ### The thrilling conclusion\n        _to our template_\n```\n\n## 顶层语法\n\n讨论类别表单的配置文件必须包含一个 `body` 键，并且 `body` 必须至少包含 1 个非 Markdown 字段。\n\n```yaml copy\nbody:\n- type: input\n  id: suggestion\n  attributes:\n    label: Suggestion\n    description: \"How might we make this project better?\"\n    placeholder: \"Adding a CODE_OF_CONDUCT.md file would be a great idea.\"\n  validations:\n    required: true\n```\n\n可以为每个讨论类别表单设置以下顶级键。\n\n| 密钥       | 说明                 | 必选 | 类型          |\n| :------- | :----------------- | :- | :---------- |\n| `body`   | 在讨论表单中定义输入类型。      | 必选 | 数组          |\n| `labels` | 将自动添加到此模板创建的讨论的标签。 | 可选 | 阵列或逗号分界的字符串 |\n| `title`  | 在讨论提交表单中预填的默认标题。   | 可选 | 字符串         |\n\n若要向表单添加字段，请在 `body` 键中包含表单元素数组。 有关可用元素及其语法的列表，请参阅 [GitHub表单架构的语法](/zh/communities/using-templates-to-encourage-useful-issues-and-pull-requests/syntax-for-githubs-form-schema)。"}