Snippets
The Snippet component enables you to reuse content across your documentation. A snippet is a chunk of content that can be inserted inside one or more topics. When you make changes to the snippet, they are made wherever the snippet is used. This can be particularly useful for boilerplate text. Snippets have their own collection in the CMS and are contained in their own separate part of the repository.
- Select the Snippet component from the Embed list.
- Edit the component.
- Choose a file from the list. The list is populated with all the files in the
/reuse/snippets/folder) every time you run the dev server or do a build.
A snippet becomes part of the topic when the site is built, rather than being fetched as the page loads. Three things follow from that:
- Site search finds the text of a snippet, under every topic that uses it.
- Headings inside a snippet appear in the topic's table of contents.
- A snippet can contain another snippet.
A snippet pointing at a file that no longer exists says so in place, the way a glossary term or a variable does:
missing-file.mdx NOT FOUND
The build still succeeds, so one wrong file name does not stop you previewing the site. The build also lists them, in case the topic is one you were not looking at.
Example
This is some content from example.mdx.
Related topics
- Code blocks and snippets – Handling code blocks in docStatic.
- URLs – Centrally managed, localizable external links.
- Conditional text – Filtering content with conditional text settings.
- Glossary terms – Localizable glossary terms with touch screen support.
- Variable sets – Localizable variables.
- Citations – Cite sources from a central CSL bibliography.