Includes

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

{{< include file="relative/path/from/hugo/root" language="go" markdown=[false|true] >}}

Attributes:

Name Usage default
file path to the included file relative to the Hugo root undefined
language language for syntax highlighting undefined
type special include type (html,page) undefined
options highlighting options linenos=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.
{{< include file="/static/_includes/example.md.part" >}}

Example Mardown include

File including a simple Markdown table.

Head 1 Head 2 Head 3
1 2 3

Language files

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

{{< include file="config.yaml" language="yaml" options="linenos=table,hl_lines=5-6,linenostart=100" >}}

Code Include:

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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
---
baseURL: https://hugo-geekblog.geekdocs.de/
title: Geekblog
theme: hugo-geekblog
pygmentsUseClasses: true
pygmentsCodeFences: true
enableGitInfo: true
timeout: 180000
pluralizeListTitles: false

paginate: 5

markup:
  goldmark:
    renderer:
      unsafe: true
  tableOfContents:
    startLevel: 1
    endLevel: 9

taxonomies:
  author: authors
  tag: tags

mediaTypes:
  "application/atom+xml":
    suffixes:
      - "xml"

outputFormats:
  Atom:
    # https://validator.w3.org/feed/docs/atom.html#whatIsAtom
    name: "Atom"
    mediaType: "application/atom+xml"
    # generated file: <baseName>.<mediaType."application/atom+xml".suffixes[0]> = atom.xml
    baseName: "feed"
    isPlainText: false
    rel: "alternate"
    isHTML: false
    noUgly: true
    permalinkable: false
  Json:
    # https://www.jsonfeed.org/2020/08/07/json-feed-version.html
    name: "Json"
    mediaType: "application/json"
    # generated file: <baseName>.<mediaType."application/feed+json".suffixes[0]> = feed.json
    baseName: "feed"
    isPlainText: false
    rel: "alternate"
    isHTML: false
    noUgly: true
    permalinkable: false

outputs:
  home:
    - HTML
    - ATOM
    - JSON
  page:
    - HTML
  section:
    - HTML
  taxonomy:
    - HTML
  term:
    - HTML
    - ATOM
    - JSON

enableRobotsTXT: true

params:
  subtitle: Subtitle to describe your blog
  description: >
    hugo-geekblog is a simple Hugo theme for personal blogs. This page is theme documentation
    and powered by the latest version of hugo-geekblog itself.    
  images:
    - "favicon/android-chrome-512x512.png"

  geekblogToC: 3
  geekblogAuthor: john-doe

  geekblogLegalNotice: https://thegeeklab.de/legal-notice/#contact-information
  geekblogPrivacyPolicy: https://thegeeklab.de/legal-notice/#privacy-policy

  geekblogImageLazyLoading: true
  geekblogDarkModeDim: true
  geekblogTagsToMenu: true

Special include types

HTML

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

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

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. Place your Markdown files within the _includes folder e.g. /_includes/include-page.md. Make sure to name it *.md.
  3. Include the page using {{< include file="/_includes/include-page.md" >}}.

Resulting structure should look like this:

_includes/
 ├── include-page.md
 └── _index.md