Includes/Snippets¶
You can include the contents of other files directly within your current file using includes. This comes in handy for admonitions and other content that you want to insert once and then use repeatedly. Rather than copying and pasting code, you only need to refer back to the original file.
You can see an example of this in the Meta section index page. This is referring back to /include/section-placeholder.md (source link).
How to¶
Markdown¶
In a Markdown page, reference an include like so:
example.md¶1 ```{include} ../include/section-placeholder.md
2 ```
Important
In the example above, remove the spaces in front of the ``` line beginnings.
Need to figure out why that’s breaking the display of this page.
Caution
When you are referencing a file in ../include, pay attention to how many sets of ../ you need to get back to the main /source level.
An easy trick for this when using VS Code is to make a blank line in your .md document, and then start dragging your include/foo.md file onto the current document. Hold Shift and then drop the file. This will give you a ‘proper’ Markdown link to the file location, which you can use in your include.