The Hoof & Paw
DocsCategoriesTagsView the current conditions from the WolfspyreLabs WeatherstationToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeBack to homepage

Includes

Include shortcode can include files of different types. By specifying a language, the included file will have syntax highlighting.

1
{{< include file="relative/path/from/hugo/root" language="go" >}}

Attributes:

NameUsagedefault
filepath to the included file relative to the Hugo rootundefined
languagelanguage for syntax highlightingundefined
typespecial include type (html,page)undefined (rendered as markdown)
optionshighlighting optionslinenos=table

Examples

Markdown file (default)

If no other options are specified, files will be rendered as Markdown using the RenderString function.

Location of markdown files
If you include markdown files that should not get a menu entry, place them outside the content folder or exclude them otherwise.
1
{{< include file="/static/_includes/example.md.part" >}}

Example Mardown include_

File including a simple Markdown table.

Head 1Head 2Head 3
123

Language files

This method can be used to include source code files and keep them automatically up to date.

1
{{< include file="config/example/config.yaml" language="yaml" options="linenos=table,hl_lines=9,linenostart=100" >}}

Result:

100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
---
baseURL: "https://example.wolfspyre.io"
title: "The Hoof and Paw - A WolfspyreLabs Blog"
theme: "hugo-geekdoc"
contentdir: "content"
layoutdir: "layouts"
publishdir: "public"
canonifyurls: true
# this example file 'config/example/config.yaml is necessary for the example snippit in content/Snippits/Geekdocs/Shortcodes/includes.md'
pygmentsUseClasses: true
pygmentsCodeFences: true
disablePathToLower: true
enableGitInfo: true

# Required if you want to render robots.txt template
enableRobotsTXT: true
description: >
  What does this button do?  

markup:
  goldmark:
    # Needed for mermaid shortcode
    renderer:
      unsafe: true
  tableOfContents:
    startLevel: 1
    endLevel: 9

taxonomies:
  tag: tags

Special include types

HTML

HTML content will be filtered by the safeHTML filter and added to the rendered page output.

1
{{< include file="/static/_includes/example.html.part" type="html" >}}

Example HTML include

This is heading 4

This is heading 5
This is heading 6

Pages

In some situations, it can be helpful to include Markdown files that also contain shortcodes. While the default method works fine to render plain Markdown, shortcodes are not parsed. The only way to get this to work is to use Hugo pages. There are several ways to structure these include pages, so whatever you do, keep in mind that Hugo needs to be able to render and serve these files as regular pages! How it works:

  1. First you need to create a directory within your content directory. For this example site _includes is used.
  2. To prevent the theme from embedding the page in the navigation, create a file _includes/_index.md and add GeekdocHidden: true to the front matter.
  3. Place your Markdown files within the _includes folder e.g. /_includes/include-page.md. Make sure to name it *.md.
  4. Include the page using {{< include file="/_includes/include-page.md" type="page" >}}.

Resulting structure should look like this:

1
2
3
_includes/
 β”œβ”€β”€ include-page.md
 └── _index.md

Example page include

This is a markdown file with a blank frontmatter header.


There is a hint shortcut in use in this markdown file:

Example Shortcode
Shortcode used in an include page.
Head 1Head 2Head 3
123

The table above generated with the following in this file.

1
2
3
4

| Head 1 | Head 2 | Head 3 |
| ------ | ------ | ------ |
| 1      | 2      | 3      |