2021-08-25 13:33:29 +02:00
+++
2022-06-05 19:31:59 +02:00
description = "Displays content from other files"
2021-08-25 13:33:29 +02:00
title = "Include"
+++
2021-08-23 22:16:08 +02:00
2022-06-05 19:31:59 +02:00
The `include` shortcode includes other files from your project inside of the current page.
2021-08-23 22:16:08 +02:00
## Usage
2024-04-12 17:30:16 +02:00
While the examples are using shortcodes with named parameter you are free to use positional as well or also call this shortcode from your own partials.
2022-06-05 19:31:59 +02:00
2023-07-27 17:02:13 +02:00
{{< tabs groupid = "shortcode-parameter" > }}
2023-06-05 23:20:37 +02:00
{{% tab title="shortcode" %}}
2022-06-05 19:31:59 +02:00
2021-08-23 23:32:34 +02:00
````go
2024-04-22 23:14:23 +02:00
{{%/* include file="shortcodes/include/INCLUDE_ME.md" */%}}
2021-08-23 22:16:08 +02:00
````
2022-06-05 19:31:59 +02:00
{{% /tab %}}
2023-06-05 23:20:37 +02:00
{{% tab title="shortcode (positional)" %}}
2021-08-28 10:08:10 +02:00
2022-06-05 19:31:59 +02:00
````go
2024-04-22 23:14:23 +02:00
{{%/* include "shortcodes/include/INCLUDE_ME.md" */%}}
2022-06-05 19:31:59 +02:00
````
2021-08-28 10:08:10 +02:00
2022-06-23 00:03:24 +02:00
{{% /tab %}}
2023-06-05 23:20:37 +02:00
{{% tab title="partial" %}}
2022-06-23 00:03:24 +02:00
````go
{{ partial "shortcodes/include .html" (dict
2023-07-27 16:14:55 +02:00
"page" .
2024-04-22 23:14:23 +02:00
"file" "shortcodes/include/INCLUDE_ME.md"
2022-06-23 00:03:24 +02:00
)}}
````
2022-06-05 19:31:59 +02:00
{{% /tab %}}
{{< / tabs > }}
2021-08-23 22:16:08 +02:00
2022-06-05 19:31:59 +02:00
The included files can even contain Markdown and will be taken into account when generating the table of contents.
2021-08-23 22:16:08 +02:00
2022-06-05 19:31:59 +02:00
### Parameter
| Name | Position | Default | Notes |
2023-07-27 16:07:01 +02:00
|----------------------|----------|------------------|-------------|
2022-06-05 19:31:59 +02:00
| **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 13:22:04 +02: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 19:31:59 +02:00
## Examples
2022-10-31 12:10:36 +01:00
### Arbitrary Content
2021-08-23 22:16:08 +02:00
2021-08-23 23:32:34 +02:00
````go
2024-04-22 23:14:23 +02:00
{{%/* include "shortcodes/include/INCLUDE_ME.md" */%}}
2021-08-23 22:16:08 +02:00
````
2022-06-05 19:31:59 +02:00
2024-04-22 23:14:23 +02:00
{{% include "shortcodes/include/INCLUDE_ME.md" %}}