Skip to main content

Shortcodes

Shortcodes are directives you can embed in your documents to insert computed values or generated content. They use the syntax {{< name arguments >}}.

Built-in shortcodes

Shortcode Description
{{< meta key >}} Insert a value from document or project metadata (dot notation supported: {{< meta book.title >}})
{{< env NAME >}} Insert the value of an environment variable; an optional second argument supplies a fallback: {{< env NAME fallback >}}
{{< var key >}} Insert a value from _variables.yml at your project root

For example, with this front matter:

---
title: My Document
version: "12.1"
---

writing {{< meta version >}} anywhere in the body inserts 12.1.

A shortcode inserts a value as it is. To compute on a metadata value, or to build markup from a list in the front matter, use an lmd cell instead.

Where shortcodes are evaluated

Shortcodes resolve in:

  • Document body text.
  • Document metadata — any front-matter value, e.g. a subtitle that interpolates {{< env PRODUCT_VERSION >}}.
  • Website configuration strings in _quarto.yml: website.title, the navbar and sidebar titles, page-footer text regions, and the text: of individual navigation items — navbar entries (including nested menu: items), sidebar contents: entries at every level, and page-footer items. These values are treated as markdown, so inline formatting and raw HTML work there too.
  • Include files (include-in-header, include-before-body, include-after-body, and {text: …} entries). Include files get textual substitution: the shortcode is replaced in place, but the surrounding file content is not otherwise interpreted as markdown.
  • Code and other text contexts — fenced code blocks, inline code, raw blocks, math, attribute values, link targets, and image sources. Like include files, these get textual substitution.

Custom shortcodes provided by extensions or by shortcodes: scripts work in all of these contexts as well.

Opting code out of substitution

Sometimes a code block should display shortcode syntax instead of evaluating it — this documentation page is full of examples. Set shortcodes="false" on a code block or inline code span to leave its text untouched:

```{.markdown shortcodes="false"}
This block displays {{< meta version >}} literally.
```

Code produced by executable cells is never substituted: the engine already processed that text, so it prints exactly what ran.

Escaping

To display a shortcode literally instead of evaluating it, use triple braces in place of double braces: writing

{{{< meta version >}}}

renders as {{< meta version >}} rather than inserting the value. The escape works in ordinary text and in all the textual contexts above (code, attributes, and so on).

Unresolved shortcodes

When a shortcode cannot be resolved — an unknown metadata key, an unset environment variable with no fallback — Quarto renders a visible ?name marker in the output and emits a warning identifying the source location, so problems are noticed rather than silently dropped.