include

Include text or Markdown from a file in the content/includes directory, with option variable substitution.

Adapted from the include shortcode in k8s.

{{< include "filename" >}}
{{< include name="filename" replace="vars,to,replace" >}}

Use {{< ... >}} delimiters with this shortcode. Otherwise, Hugo will process the full shortcode’s content through Markdown processing, adding extraneous markup.

Variable substitution is meant for content. It does not work in other shortcodes, like relrefs.


Examples

Without Variable Substitution

{{< include "anchor-ip" >}}

Renders to:

Droplets created from a custom image do not receive an anchor IP address and do not require one to use a reserved IP. When you assign a reserved IP address to a Droplet created from a custom image, the reserved IP is automatically mapped to the Droplet’s public IPv4 address instead of an anchor IP.

With Variable Substitution

The Markdown file that generates this page contains these front matter variables:

examplefm: foo bar
anotherexample: baz quux

The Markdown file includes/style-example.md has the content:

Here's an example in which "REPLACE-EXAMPLEFM" and "REPLACE-ANOTHEREXAMPLE" are replaced.

So the following shortcode call:

{{< include name="style-example" replace="examplefm,anotherexample" >}}

Renders to:

Here’s an example in which “foo bar” and “baz quux” are replaced.

Known Issues

As k8s points out, shortcodes inside include statements will break the build. You must insert them in the parent document, before and after you call the include. For example:

{{< notice note >}}
{{< include "anchor-ip" >}}
{{< /notice >}}

Renders to:

Note
Droplets created from a custom image do not receive an anchor IP address and do not require one to use a reserved IP. When you assign a reserved IP address to a Droplet created from a custom image, the reserved IP is automatically mapped to the Droplet’s public IPv4 address instead of an anchor IP.