2021-08-25 11:33:29 +00:00
+++
2022-06-05 17:31:59 +00:00
description = "Displays content from other files"
2021-08-25 11:33:29 +00:00
title = "Include"
+++
2021-08-23 20:16:08 +00:00
2022-06-05 17:31:59 +00:00
The `include` shortcode includes other files from your project inside of the current page.
2021-08-23 20:16:08 +00:00
## Usage
2022-06-22 22:03:24 +00:00
While the examples are using shortcodes with named parameter you are free to use positional aswell or also call this shortcode from your own partials.
2022-06-05 17:31:59 +00:00
{{< tabs groupId = "shortcode-parameter" > }}
2022-06-22 22:03:24 +00:00
{{% tab name="shortcode" %}}
2022-06-05 17:31:59 +00:00
2021-08-23 21:32:34 +00:00
````go
2022-06-05 17:31:59 +00:00
{{%/* include file="shortcodes/INCLUDE_ME.md" */%}}
2021-08-23 20:16:08 +00:00
````
2022-06-05 17:31:59 +00:00
{{% /tab %}}
2022-06-22 22:03:24 +00:00
{{% tab name="shortcode (positional)" %}}
2021-08-28 08:08:10 +00:00
2022-06-05 17:31:59 +00:00
````go
{{%/* include "shortcodes/INCLUDE_ME.md" */%}}
````
2021-08-28 08:08:10 +00:00
2022-06-22 22:03:24 +00:00
{{% /tab %}}
{{% tab name="partial" %}}
````go
{{ partial "shortcodes/include .html" (dict
"context" .
"file" "shortcodes/INCLUDE_ME.md"
)}}
````
2022-06-05 17:31:59 +00:00
{{% /tab %}}
{{< / tabs > }}
2021-08-23 20:16:08 +00:00
2022-06-05 17:31:59 +00:00
The included files can even contain Markdown and will be taken into account when generating the table of contents.
2021-08-23 20:16:08 +00:00
2022-06-05 17:31:59 +00:00
### Parameter
| Name | Position | Default | Notes |
|:---------------------|:---------|:-----------------|:------------|
| **file** | 1 | _<empty>_ | The path to the file to be included. Path resolution adheres to [Hugo's build-in `readFile` function ](https://gohugo.io/functions/readfile/ ) |
2022-06-23 11:22:04 +00:00
| **hidefirstheading** | 2 | `false` | When `true` and the included file contains headings, the first heading will be hidden. This comes in handy, eg. if you include otherwise standalone Markdown files. |
2022-06-05 17:31:59 +00:00
## Examples
### Arbitray Content
2021-08-23 20:16:08 +00:00
2021-08-23 21:32:34 +00:00
````go
2021-08-23 20:16:08 +00:00
{{%/* include "shortcodes/INCLUDE_ME.md" */%}}
````
2022-06-05 17:31:59 +00:00
{{% include "shortcodes/INCLUDE_ME.md" %}}