<!--
  canonical-url: https://www.avonture.be/blog/quarto-includes-shortcode
  published:     2024-04-13
  This is a static plain-Markdown mirror generated at build time.
  Visit the canonical URL above for the fully rendered page, with images and interactive components.
-->

# Quarto includes short code

> Learn how to use the Quarto includes short code to break down long documents into multiple, organized files, making your writing process easier.

---
![Quarto includes short code](/img/v2/quarto.webp)

**TL;DR**

This article shows Quarto's `{{< include >}}` short code, which lets you split a long document into several smaller Markdown files and merge them at render time by referencing their relative paths from a main `.qmd` file.

Using the Quarto `includes` short code, writing a long document can easily be broken down into several smaller ones.

*`includes` splits a document into fixed chunks. When the repeated part is the same *structure* filled with different values, [Using Mustache templating with Quarto](/blog/quarto-mustache) and [Using variables from external file in your Quarto project](/blog/quarto-project-variables) are the right tools.*

Imagine the following `main.qmd` file:

**main.qmd**

```qmd
# My thesis in Latin

{{< include chapter1.md >}}

{{< include chapter2.md >}}
```

Quarto will then merge the three files when you render `main.qmd`.

> **Docker image with Quarto:**
>
> If you don't have yet a Docker image with Quarto, read this article [Running Quarto Markdown in Docker](/blog/docker-quarto).

## Includes tag

The tag is simple, you just need to specify the relative path to the file to include. Get in-depth syntax on the [official documentation](https://quarto.org/docs/authoring/includes.html).

## Result

Running `quarto render main.qmd --to html` on the `main.qmd` file shown above merges the
included files into one document:

![Quarto includes](./images/includes.webp)

Here's what's actually inside each included file.

Here is some dummy content for `chapter1.md`:

**chapter1.md**

```markdown
## Chapter 1

Voluptatem minus labore architecto sed voluptas molestiae perferendis. Sed voluptatem ut amet at blanditiis sunt et exercitationem quidem. Vel id impedit dicta omnis repudiandae iure.

Expedita magni facere. Ullam non non sint qui provident. Ea beatae voluptatem pariatur. Et beatae error ea aut neque omnis pariatur rerum ut.

Ad aut nobis magni aut est dicta adipisci est. Quo reiciendis eum aut rem. Dolores sit magni non.
```

And for `chapter2.md`:

**chapter2.md**

```markdown
## Chapter 2

Iure repudiandae perferendis maiores dolorem consequuntur exercitationem suscipit.

Animi voluptatem est quia. Quia id optio. Architecto ut ipsa voluptas minima voluptate accusamus architecto.

Consequatur debitis et sunt eos quod qui unde aut.
```

Now, by running, f.i., `quarto render main.qmd --to html`, Quarto will merge these two files (and `main.qmd`) into the rendered page shown above.

> **What is a `.qmd` file?:**
>
> For Quarto, the extension isn't very important: whether it's `.qmd` or `.md`, there's no difference in treatment.
>
> On the other hand, it's probably more interesting for us to use the `.qmd` extension when using a Quarto-specific syntax, as is the case here.
