Sub topic 4
Markdown issue templates
This chapter assumes you can create files in a repository, read basic YAML, and know that issues and pull requests are separate things on GitHub. It covers the older, simpler way to template issues: a Markdown file with a small block of front matter. The next chapter covers YAML issue forms, which are more structured.
What a Markdown issue template is
A Markdown issue template is a .md file in the .github/ISSUE_TEMPLATE/ folder. When a contributor opens a new issue, GitHub shows a chooser listing each template. After they pick one, the issue body is pre-filled with the file's Markdown content.
Unlike the single pull request template, you can keep several issue templates side by side. Each file becomes one entry in the chooser.
Front matter
Front matter is a block of YAML at the top of the file, between two lines of ---. GitHub reads it to build the chooser entry and to set defaults on the new issue. The body below it is the text the contributor edits.
---
name: Feature request
about: Suggest an idea for this project
title: "[Feature]: "
labels: enhancement
assignees: ""
---
## Problem
What problem would this feature solve?
## Proposed solution
Describe what you would like to happen.Save this as .github/ISSUE_TEMPLATE/feature_request.md. The front matter keys work as follows.
| Key | Purpose |
|---|---|
| `name` | The template's name in the chooser. Required. |
| `about` | A one-line description shown under the name. Required. |
| `title` | Default issue title. Contributors can change it. |
| `labels` | Labels applied when the issue is created. |
| `assignees` | Users assigned when the issue is created. |
Both name and about are required. The other keys are optional.
How the pieces fit together
The sequence below shows what happens when a contributor uses the template.
Writing the body
The body is ordinary Markdown. Two habits make it work better.
- Use headings for each piece of information you need. Contributors then fill in text under each heading.
- Use HTML comments such as
<!-- Describe the steps here -->for instructions. Comments do not appear in the rendered issue, so they guide the writer without cluttering the result.
Common errors
Most problems with Markdown templates come from the front matter.
- Missing
nameorabout. The template may not appear in the chooser. Include both. - Unquoted special characters. A title such as
[Feature]:begins with[, which YAML reads as a list. Wrap it in quotes, as the example does. - Labels that do not exist. GitHub applies only labels that already exist in the repository. If a label is missing, create it first.
- Assignees without access. Only users who can be assigned to issues in the repository are applied.
- Wrong folder or branch. The file must be in
.github/ISSUE_TEMPLATE/on the default branch.
Limits of Markdown templates
A Markdown template pre-fills text, and nothing more. It cannot make a section required, offer a dropdown, or check that the contributor kept the headings. Contributors can delete your prompts or submit the template untouched. If you need required fields or consistent structure, use an issue form, which the next chapter introduces.
Exercise
A Markdown issue template does not show up in the chooser, and its title value is [Bug]: . Name two things to check.
Show answer
First, confirm the file is in .github/ISSUE_TEMPLATE/ on the default branch and that the front matter includes both name and about. Second, check the title value. It starts with [, so it must be wrapped in quotes (title: "[Bug]: "), or YAML will misread it as a list.
Exercise
Why might you choose a YAML issue form over a Markdown template?
Show answer
A Markdown template only pre-fills text, so contributors can ignore or delete any part of it. An issue form can make fields required and use dropdowns, which gives you more consistent reports.