Mine Çetinkaya-Rundel


July 1, 2022


If you have content you want to include across many files, you can place that content in a separate Quarto file and use the include comment wherever you want to pull it in.

This could be useful for plain text content (e.g., including the same submission instructions for each homework assignment) or for content that includes computation (e.g., including the same data cleaning steps for various alternate analyses).

Suppose you have such repeatable content in a file called _content-to-repeat.qmd and suppose the contents of that file read Look at me, I’m content to be repeated! (in italics):


*Look at me, I'm content to be repeated!*

You can include it in other documents using the {{< include >}} shortcode:

{{< include _content-to-repeat.qmd >}}

This will result in:

Look at me I’m content to be repeated!

A few important things to note:

  • The name of the file that will be included should start with an underscore (_) so that they are automatically ignored (i.e. not treated as standalone files) when rendering a project.
  • All computations within a document will share a single engine (e.g., knitr and jupyter), which is relevant when the included file has computations.
  • The included file does not have to be a .qmd if it only contains text, it can also be a .md, .ipynb, etc. However included files with computation in them need to be .qmd, computational includes don’t work in .ipynb notebook files.

Learn more