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:

Name Description 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 (rendered as markdown)
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.

Important

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 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.

1







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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
languageCode = 'en-us'
MetaDataFormat = "yaml"
title = 'Hugo Cosmos'
enableGitInfo = true
enableRobotsTXT = true
theme = "hugo-theme-cosmos"
baseURL = "https://hugo-theme-cosmos.netlify.app/"
googleAnalytics = 'G-ST7MVBC6EK'

[menu]
  span>.    title = "documentation"
    name = "book"
    url = "/docs/"
    weight = -50
  span>.    title = "garden"
    name = "brain"
    url = "/garden/"
    weight = -40
  span>.    title = "github"
    name = "github"
    url = "https://github.com/librabyte/hugo-theme-cosmos"
    weight = -30
  span>.    title = "rss"
    name = "rss"
    url = "/index.xml"
    weight = -20


[markup]
  [markup.highlight]
    style = 'monokai'
    codeFences = true
    guessSyntax = false
    lineNoStart =1
    lineNos = true
    lineNumbersInTable = true

  [markup.tableOfContents]
    endLevel = 6
    ordered = false
    startLevel = 2

  [markup.goldmark.renderer]
    unsafe = true


[module]
  [module.mounts]
    source = 'assets'
    target = 'assets'


[params]
  since = "2019"
  dateFormat = "January 2, 2006"

  enableHomeProfile = false
  mainSections = ["posts"]
  bookSection = "docs"
  photoSwipe = false

  # (Optional, default false) Enables SEO with google analytics.
  googleAnalytics = true
  # (Optional, default false) Enables search function with fuse.js.
  search = true
  # (Optional, default true) Display a "Back to top" link in the site footer.
  back2top = true
  # (Optional, default true) Enable douban short code for douban music/book reference.
  douban = true
  # (Optional, default true) Enable Table of Contents in the right sidebar.
  toc = true
  # (Optional, default true) always collapse in the file tree mode.
  alwaysCollapse = true

  # (Optional, default false) enable wikilink feature.
  [params.wikilink]
    enableWikilink = true
    enableBacklinks = true
    enableLinkPreview = false

  # (Optional, default true) Enable giscus as comment plugin.
  [params.comments.giscuss]
    enable = true
    repo = "librabyte/hugo-theme-cosmos"
    repoId = "R_kgDOIEDNvg"
    category = "Announcements"
    categoryId = "DIC_kwDOIEDNvs4CTiKG"
    theme = "light"

  [params.reward]
    enable = true
    [params.reward.items]
      wechat = "https://cosmos-1251905798.cos.ap-beijing.myqcloud.com/theme/wechatpay.png"
      alipay = "https://cosmos-1251905798.cos.ap-beijing.myqcloud.com/theme/alipay.jpg"

  [params.copyright]
    # (Optional, default true) Enable copyright info display in the post footer.
    enable = true
    content = '<a rel="license noopener" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank">CC BY-NC-ND 4.0</a>'
    [params.copyright.gitInfo]
      gitRepo = "https://github.com/librabyte/hugo-theme-cosmos"
      showCommitMessage = true

  [params.markmap]
    enable = true

  [params.mermaid]
    enable = true

  [params.echarts]
    # enable/disable ECharts support
    enable = true
    map = true

  [params.katex]
    # enable/disable KaTeX support
    enable = true

[outputs]
  home = ["HTML", "RSS", "JSON"]

[sitemap]
  changefreq = 'monthly'
  filename = 'sitemap.xml'
  priority = 0.5

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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
languageCode = 'en-us'
MetaDataFormat = "yaml"
title = 'Hugo Cosmos'
enableGitInfo = true
enableRobotsTXT = true
theme = "hugo-theme-cosmos"
baseURL = "https://hugo-theme-cosmos.netlify.app/"
googleAnalytics = 'G-ST7MVBC6EK'

[menu]
  span>.    title = "documentation"
    name = "book"
    url = "/docs/"
    weight = -50
  span>.    title = "garden"
    name = "brain"
    url = "/garden/"
    weight = -40
  span>.    title = "github"
    name = "github"
    url = "https://github.com/librabyte/hugo-theme-cosmos"
    weight = -30
  span>.    title = "rss"
    name = "rss"
    url = "/index.xml"
    weight = -20


[markup]
  [markup.highlight]
    style = 'monokai'
    codeFences = true
    guessSyntax = false
    lineNoStart =1
    lineNos = true
    lineNumbersInTable = true

  [markup.tableOfContents]
    endLevel = 6
    ordered = false
    startLevel = 2

  [markup.goldmark.renderer]
    unsafe = true


[module]
  [module.mounts]
    source = 'assets'
    target = 'assets'


[params]
  since = "2019"
  dateFormat = "January 2, 2006"

  enableHomeProfile = false
  mainSections = ["posts"]
  bookSection = "docs"
  photoSwipe = false

  # (Optional, default false) Enables SEO with google analytics.
  googleAnalytics = true
  # (Optional, default false) Enables search function with fuse.js.
  search = true
  # (Optional, default true) Display a "Back to top" link in the site footer.
  back2top = true
  # (Optional, default true) Enable douban short code for douban music/book reference.
  douban = true
  # (Optional, default true) Enable Table of Contents in the right sidebar.
  toc = true
  # (Optional, default true) always collapse in the file tree mode.
  alwaysCollapse = true

  # (Optional, default false) enable wikilink feature.
  [params.wikilink]
    enableWikilink = true
    enableBacklinks = true
    enableLinkPreview = false

  # (Optional, default true) Enable giscus as comment plugin.
  [params.comments.giscuss]
    enable = true
    repo = "librabyte/hugo-theme-cosmos"
    repoId = "R_kgDOIEDNvg"
    category = "Announcements"
    categoryId = "DIC_kwDOIEDNvs4CTiKG"
    theme = "light"

  [params.reward]
    enable = true
    [params.reward.items]
      wechat = "https://cosmos-1251905798.cos.ap-beijing.myqcloud.com/theme/wechatpay.png"
      alipay = "https://cosmos-1251905798.cos.ap-beijing.myqcloud.com/theme/alipay.jpg"

  [params.copyright]
    # (Optional, default true) Enable copyright info display in the post footer.
    enable = true
    content = '<a rel="license noopener" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank">CC BY-NC-ND 4.0</a>'
    [params.copyright.gitInfo]
      gitRepo = "https://github.com/librabyte/hugo-theme-cosmos"
      showCommitMessage = true

  [params.markmap]
    enable = true

  [params.mermaid]
    enable = true

  [params.echarts]
    # enable/disable ECharts support
    enable = true
    map = true

  [params.katex]
    # enable/disable KaTeX support
    enable = true

[outputs]
  home = ["HTML", "RSS", "JSON"]

[sitemap]
  changefreq = 'monthly'
  filename = 'sitemap.xml'
  priority = 0.5

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